diff options
author | Joseph Hunkeler <jhunk@stsci.edu> | 2011-03-25 00:13:58 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunk@stsci.edu> | 2011-03-25 00:13:58 -0400 |
commit | c2e02f5589bf53cfb7a020de59e2821261b3fffb (patch) | |
tree | 92284dbff8dcf491ee5b7b7ec721eb018440351c | |
parent | 4dc277e0621d8dfd9afcb41e355f8663a0d8e3eb (diff) | |
download | duser-c2e02f5589bf53cfb7a020de59e2821261b3fffb.tar.gz |
Need to work around writing as binary. Otherwise almost functional.
find_in_file_ex needs tweaking for return value
-rw-r--r-- | duser.c | 16 |
1 files changed, 9 insertions, 7 deletions
@@ -59,7 +59,8 @@ int user_del(record_t* rec) int fd; int verify; char buf[REGEX_MAX]; - char tmpfile[255] = "/tmp/duser.XXXXXX"; + char tmpfile[255]; + snprintf(tmpfile, sizeof(tmpfile), "/tmp/duser.%s.XXXXXX", basename(rec->file)); if((fd = mkstemp(tmpfile)) < 0 || (tfp = fdopen(fd, "w+")) == NULL) { if(fd != -1) @@ -79,11 +80,10 @@ int user_del(record_t* rec) while(!feof(fp)) { + memset(buf, 0, sizeof(buf)); fgets(buf, REGEX_MAX, fp); - if((verify = find_in_file_ex(rec)) != -1) - continue; - else - fputs(buf, tfp); + if((verify = find_in_file_ex(rec))) + write(fd, buf, sizeof(buf)); } fclose(fp); @@ -95,7 +95,8 @@ int user_del(record_t* rec) // VERIFY that the record is proper (useful for deletion of users) int find_in_file_ex(record_t* rec) { - int index_local = 0; + int index_temp = 0; + int index_local = -1; char buf[REGEX_MAX]; FILE *fp; @@ -109,8 +110,9 @@ int find_in_file_ex(record_t* rec) { fgets(buf, REGEX_MAX, fp); buf[strlen(buf) - 1] = '\0'; + index_temp++; if((strcmp(buf, rec->name)) != 0) - index_local++; + index_local = index_temp; else break; } |