Linux C Programs (14)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.