aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunk@stsci.edu>2011-03-25 10:19:30 -0400
committerJoseph Hunkeler <jhunk@stsci.edu>2011-03-25 10:19:30 -0400
commit400c80e68042ad48d7e825bab35b78f96cb7a1d7 (patch)
tree6e68b54e958e928a696db3e4f6e92e337de508fa
parentc2e02f5589bf53cfb7a020de59e2821261b3fffb (diff)
downloadduser-400c80e68042ad48d7e825bab35b78f96cb7a1d7.tar.gz
user_del is now capable of removing text from the temp files.
still does not modify original files
-rw-r--r--duser.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/duser.c b/duser.c
index 07e8144..f31e57b 100644
--- a/duser.c
+++ b/duser.c
@@ -82,8 +82,12 @@ int user_del(record_t* rec)
{
memset(buf, 0, sizeof(buf));
fgets(buf, REGEX_MAX, fp);
- if((verify = find_in_file_ex(rec)))
- write(fd, buf, sizeof(buf));
+ buf[strlen(buf) - 1] = '\0';
+ if((strcmp(buf, rec->name)) != 0 )
+ {
+ buf[strlen(buf)] = '\n';
+ write(fd, buf, strlen(buf));
+ }
}
fclose(fp);
@@ -95,30 +99,29 @@ 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_temp = 0;
- int index_local = -1;
+ int match = -1;
char buf[REGEX_MAX];
FILE *fp;
if((fp = fopen(rec->file, "r")) == NULL)
{
perror("find_in_file_ex");
- return index_local;
+ return -1;
}
while(!feof(fp))
{
fgets(buf, REGEX_MAX, fp);
buf[strlen(buf) - 1] = '\0';
- index_temp++;
- if((strcmp(buf, rec->name)) != 0)
- index_local = index_temp;
- else
+ if((strcmp(buf, rec->name)) == 0)
+ {
+ match = 0;
break;
+ }
}
fclose(fp);
- return index_local;
+ return match;
}
record_t* find_in_file(const char* filename, const char* needle)