Mercurial > hg > mlmmj
changeset 72:42d75f6f0a3d
changed incindexfile() - removed incflag, changed error return to be 0, and it now saves last used index in the file
author | mortenp |
---|---|
date | Wed, 12 May 2004 01:50:04 +1000 |
parents | 489a2ecafb36 |
children | 420d5997f1d9 |
files | include/incindexfile.h src/incindexfile.c src/mlmmj-send.c |
diffstat | 3 files changed, 25 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/include/incindexfile.h Mon May 10 22:22:21 2004 +1000 +++ b/include/incindexfile.h Wed May 12 01:50:04 2004 +1000 @@ -9,6 +9,6 @@ #ifndef INCINDEXFILE_H #define INCINDEXFILE_H -int incindexfile(const char *listdir, int incflag); +int incindexfile(const char *listdir); #endif /* INCINDEXFILE_H */
--- a/src/incindexfile.c Mon May 10 22:22:21 2004 +1000 +++ b/src/incindexfile.c Wed May 12 01:50:04 2004 +1000 @@ -14,56 +14,58 @@ #include <fcntl.h> #include <unistd.h> #include <string.h> + #include "wrappers.h" #include "mylocking.h" #include "incindexfile.h" #include "itoa.h" #include "log_error.h" +#include "strgen.h" #define INTBUF_SIZE 32 -int incindexfile(const char *listdir, int incflag) +int incindexfile(const char *listdir) { - size_t len; int fd, lock; - long int mindex = 0, oldindex = 0; + long int index = 0; char intbuf[INTBUF_SIZE] = "uninitialized"; - int s; + size_t i; char *indexfilename; - len = strlen(listdir) + strlen("/index") + 1; - indexfilename = malloc(len); - snprintf(indexfilename, len, "%s%s", listdir, "/index"); + indexfilename = concatstr(2, listdir, "/index"); fd = open(indexfilename, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); if(fd == -1) { + free(indexfilename); log_error(LOG_ARGS, "Error opening index file"); - return -1; + return 0; } lock = myexcllock(fd); if(lock) { + free(indexfilename); log_error(LOG_ARGS, "Error locking index file"); close(fd); - return -1; + return 0; } read(fd, intbuf, INTBUF_SIZE); - for(s = INTBUF_SIZE - 1; s >= 0; s--) - if(intbuf[s] < '0' || intbuf[s] > '9') - intbuf[s] = 0; - oldindex = atol(intbuf); - if(incflag) { - mindex = oldindex; - mindex++; - itoa(mindex, intbuf); + for(i=0; i<sizeof(intbuf); i++) { + if(intbuf[i] < '0' || intbuf[i] > '9') { + intbuf[i] = '\0'; + break; + } + } + index = atol(intbuf); + index++; + itoa(index, intbuf); lseek(fd, 0, SEEK_SET); writen(fd, intbuf, strlen(intbuf)); - } + myunlock(fd); close(fd); free(indexfilename); - return oldindex; + return index; }
--- a/src/mlmmj-send.c Mon May 10 22:22:21 2004 +1000 +++ b/src/mlmmj-send.c Wed May 12 01:50:04 2004 +1000 @@ -275,7 +275,7 @@ /* initialize the archive filename */ if(listctrl[0] != '1' && listctrl[0] != '2') { - mindex = incindexfile((const char *)listdir, 1); + mindex = incindexfile((const char *)listdir); len = strlen(listdir) + 9 + 20; archivefilename = malloc(len); snprintf(archivefilename, len, "%s/archive/%d", listdir,