I have written a password program in c. and I saved the password in a text file using some encryptiion and retrieving the old password from a file using decryption techniques So that user cannot see the password.Yes ofcourse this might not be the efficient way to do because there is a chance for user to delete the text file.
But still I want to lock (protect) a file using my c password code.I have searched on google I found perl can be used to lock a file.The question is that possible in c? Do we have any function like flock in perl? or suggest me some functions that can be helpful to develop a file lock function in c.becuase People may say we have c# and lots of stuff out to lock a file and why your sticking to c? but I like challenging the things.So please let me know If theres something I need to learn.Thank you in advance.
You can, on a POSIX system, use
fcntl()along with theF_SETLKvalue for the command argument, and then setF_WRLCK(i.e, and exclusive lock) in thestruct flockdata-memberl_type.So for instance (add your own error-detection mechanisms):