Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get file information similar to "ls -la" using C?

Tags:

c

file

unix

struct

I am using ar.h for the defining the struct. I was wondering on how I would go about getting information about a file and putting it into those specified variables in the struct.

struct ar_hdr {
    char ar_name[16];       /* name of this member */
    char ar_date[12];       /* file mtime */
    char ar_uid[6];         /* owner uid; printed as decimal */
    char ar_gid[6];          /* owner gid; printed as decimal */
    char ar_mode[8];        /* file mode, printed as octal   */
    char ar_size[10];       /* file size, printed as decimal */
    char ar_fmag[2];        /* should contain ARFMAG */
};

Using the struct defined above, how would I put get the information from the file from ls -la

-rw-rw----. 1 clean-unix upg40883 368 Oct 29 15:17 testar

?

like image 718
inoobdotcom Avatar asked Dec 22 '22 07:12

inoobdotcom


1 Answers

You're looking for stat(2,3p).

like image 162
Ignacio Vazquez-Abrams Avatar answered Dec 24 '22 01:12

Ignacio Vazquez-Abrams