File Operations (Linux system programming)
When you create a directory, the system automatically creates two directories. and.
C language Implement permission control function
1#include <stdio.h>2#include <stdlib.h>3#include <sys/types.h>4#include <sys/stat.h>5 6 intMainintARGC,Char**argv) {7 intmode;8 intMode_u;9 intMode_g;Ten intmode_o; One Char*path; A - if(ARGC <3){ -printf"%s<mode num> <target file>\n", argv[0]); theExit0); - } - //string conversion to Integer type -mode = Atoi (argv[1]); + if(Mode >777|| Mode <0){ -printf"mode num Error! \ n"); +Exit0); A } at -Mode_u = mode/ -; -Mode_g = (Mode-(mode_u* -)) /Ten; -Mode_o = mode-(mode_u* -)-(mode_g*Ten); -mode = (Mode_u *8*8) + (Mode_g *8) +mode_o; -Path = argv[2]; in //Change permission function - if(chmod (path, mode) = =-1){ toPerror ("chmod Error"); +Exit1); - } the * return 0; $ }Panax Notoginseng - Create a new file test.c theCommand:./program444TEST.c
Linux C Programs (14)