unix - C How to stop file from being overwritten -


currently the file gets created , overwritten. trying if file exists exits program. open must used.

if ((dest = open(argv[2], o_wronly | o_creat, 0644)) == -1) {     printf("error file %s exists", argv[2]);     return 3;   } 

just use o_excl:

o_excl ensure call creates file: if flag specified in conjunction o_creat, and pathname exists, open() fail.