.


:




:

































 

 

 

 


, .




, . .

:

#include <sys/types.h>

#include <sys/stat.h>

#include <unistd.h>

:

int stat(const char *filename, struct stat *buf); -

: st_mode /* , */

:

S_IFMT 0170000

S_IFREG 0100000

S_IFDIR 0040000

student@loony ~/new $ ls -lF

-rwx------ 3 student student 187 2012-12-23 17:20 1.c*

drwxrwxr-x 2 student student 4096 2012-12-23 16:48 p1/

-rwxrwxr-x 1 student student 8623 2012-12-23 20:29 prog*

lrwxrwxrwx 1 student student 2 2012-12-23 17:22 s1 -> p1/

lrwxrwxrwx 1 student student 3 2012-12-23 17:24 s3 -> 1.c*

student@loony ~/new $./prog s1

s1:

student@loony ~/new $./prog s3

s3:

 

:

#include <sys/types.h>

#include <sys/stat.h>

#include <unistd.h>

#include <stdio.h>

int main(int argc, char **argv)

{struct stat s; stat(argv[1], &s);

int q; static char str[22];

q=s.st_mode & S_IFMT;

switch (q)

{ case S_IFREG: sprintf(str," "); break;

case S_IFDIR: sprintf(str,""); break;

default: sprintf(str,"???"); break;}

fprintf(stdout," %s: %s\n",argv[1],str);}

, . .

:

#include <sys/types.h>

#include <sys/stat.h>

#include <unistd.h>

:

int stat(const char *filename, struct stat *buf); -

: st_mode /* , */

:

S_IFMT 0170000

S_IFDIR 0040000

student@loony ~/new $ ls -lF

-rwx------ 3 student student 187 2012-12-23 17:20 1.c*

drwxrwxr-x 2 student student 4096 2012-12-23 16:48 p1/

-rwxrwxr-x 1 student student 8623 2012-12-23 20:29 prog*

lrwxrwxrwx 1 student student 2 2012-12-23 17:22 s1 -> p1/

lrwxrwxrwx 1 student student 3 2012-12-23 17:24 s3 -> 1.c*

student@loony ~/new $./prog s1

s1:

student@loony ~/new $./prog 1.

1.:???

 

:

#include <sys/types.h>

#include <sys/stat.h>

#include <unistd.h>

#include <stdio.h>

int main(int argc, char **argv)

{struct stat s; stat(argv[1], &s);

int q; static char str[22];

q=s.st_mode & S_IFMT;

switch (q)

{case S_IFDIR: sprintf(str,""); break;

default: sprintf(str,"???"); break;}

fprintf(stdout," %s: %s\n",argv[1],str);}

, . .

:

#include <sys/types.h>

#include <sys/stat.h>

#include <unistd.h>

:

int lstat(const char *filename, struct stat *buf); -

: st_mode /* , */

:

S_IFMT 0170000

S_IFLNK 0120000

S_IFREG 0100000

S_IFDIR 0040000

student@loony ~/new $ ls -lF

-rwx------ 3 student student 187 2012-12-23 17:20 1.c*

drwxrwxr-x 2 student student 4096 2012-12-23 16:48 p1/

-rwxrwxr-x 1 student student 8623 2012-12-23 20:29 prog*

lrwxrwxrwx 1 student student 2 2012-12-23 17:22 s1 -> p1/

lrwxrwxrwx 1 student student 3 2012-12-23 17:24 s3 -> 1.c*

student@loony ~/new $./prog s1

s1: C

student@loony ~/new $./prog p1

p1:

student@loony ~/new $./prog 1.c

1.:

:

#include <sys/types.h>

#include <sys/stat.h>

#include <unistd.h>

#include <stdio.h>

int main(int argc, char **argv)

{ struct stat lst; lstat(argv[1], &lst);

int q; static char str[22];

switch (lst.st_mode & S_IFMT)

{case S_IFLNK: sprintf(str,"C "); break;

case S_IFREG: sprintf(str," "); break;

case S_IFDIR: sprintf(str,""); break;

default: sprintf(str,"???"); break;}

fprintf(stdout," %s: %s\n",argv[1],str);}

, . .

:

#include <sys/types.h>

#include <sys/stat.h>

#include <unistd.h>

:

int lstat(const char *filename, struct stat *buf); -

: st_mode /* , */

:

S_IFMT 0170000

S_IFLNK 0120000

student@loony ~/new $ ls -lF

-rwx------ 3 student student 187 2012-12-23 17:20 1.c*

drwxrwxr-x 2 student student 4096 2012-12-23 16:48 p1/

-rwxrwxr-x 1 student student 8623 2012-12-23 20:29 prog*

lrwxrwxrwx 1 student student 2 2012-12-23 17:22 s1 -> p1/

lrwxrwxrwx 1 student student 3 2012-12-23 17:24 s3 -> 1.c*

student@loony ~/new $./prog s1

s1: C

student@loony ~/new $./prog 1.

1.:???

student@loony ~/new $./prog p1

p1:???

#include <sys/types.h>

#include <sys/stat.h>

#include <unistd.h>

#include <stdio.h>

int main(int argc, char **argv)

{ struct stat lst; lstat(argv[1], &lst);

int q; static char str[22];

switch (lst.st_mode & S_IFMT)

{case S_IFLNK: sprintf(str,"C "); break;

default: sprintf(str,"???"); break;}

fprintf(stdout," %s: %s\n",argv[1],str);}





:


: 2015-10-27; !; : 345 |


:

:

.
==> ...

1267 - | 1248 -


© 2015-2024 lektsii.org - -

: 0.017 .