Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task 2: Printing the time that the file path was created (50 points) The stat system call can access a file by name and retrieve

image text in transcribed
Task 2: Printing the time that the file path was created (50 points) The stat system call can access a file by name and retrieve file status information. It is given by: int stat (const char *pathname, struct stat *buf): This system call returns a stat structure (both the function and struct are called stat), which contains the following fields: struct stat Adev_t sl_dev; /* ID of device containing file * ino_tsuino; inode number mode_1st_mode; /* protection inlink_tst_nlink; /* number of hard links */ uid_ s_uid; /* user ID of owner gid_t sl_gid; /* group ID of owner * dev_t surdev; /* device ID (if special file) bff_ts_size; /* total size, in bytes / blksize_t sublksize; /*blocksize for file system 1/0 */ plkcnt_tst_blocks; /* number of 512B blocks allocated kime_t st_atime; /* time of last access * kime_t si_mtime; /* time of last modification/ kime_tst_ctime;/" time of last status change On success, zero is returned. On error, -1 is returned, and errno is set appropriately. The following program displays the time that the file path was last accessed. Type in and complete the following program on the computer. Save it as printaccess.c. Compile the program, then execute it by giving it a path name as an argument. printaccess.co #include #include #include int main(int arge, char *argv[]) // define an instance of struct stat don't use a pointer). // Use the stat function store the status of the file in your stat struct // stat takes a pointer, so pass your struct by reference with & // use perror to print error message then exit program } // print the last access time for the file using defined instance of // struct stat. ctime requires a pointer, hence the & below. printf ("%s last accessed at %s", argv[1], ctime(& _.st_atime))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

More Books

Students also viewed these Databases questions

Question

5-8 What are the advantages and disadvantages of cloud computing?

Answered: 1 week ago