Last active
July 3, 2017 09:56
-
-
Save madcoder2k17/93ebad95c0271f3eaf355693bd7fc626 to your computer and use it in GitHub Desktop.
This snippet submitted by jAs™ and copyright ©jAs MLt. Ltd.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <fcntl.h> | |
#include <sys/stat.h> | |
#include <sys/types.h> | |
#include <errno.h> | |
char* program_name; | |
void system_error(char* cause, int exit_code) | |
{ | |
fprintf(stderr,"%s: %s: %s\n",program_name,cause, (char*) strerror(errno)); | |
exit(exit_code); | |
} | |
int main(int argc, char **argv) | |
{ | |
if(argc != 2) | |
{ | |
printf("Usage: %s <filename>\n",argv[0]); | |
exit(EXIT_FAILURE); | |
} | |
program_name = argv[0]; | |
/* Permisions for the new file */ | |
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH; | |
/* filename for the new file */ | |
char* filename = argv[1]; | |
/* Create a new file */ | |
int fd = open(filename,O_CREAT | O_EXCL,mode); | |
if(fd == -1) | |
{ | |
system_error("open",EXIT_FAILURE); | |
} | |
exit(EXIT_SUCCESS); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment