[ekg2-commit] ekg2: drafts.c (HEAD) [peres]
CVS commit
cvs w toxygen.net
Pon, 7 Maj 2007, 10:23:03 CEST
Module name: ekg2
Changes by: peres 2007-05-07 10:23:01
Modified files:
drafts.c
Log message:
ekg_openfile() -> ekg_checkoutfile() - most universal name I could find out.
Also, slightly modifying behavior - if we pass hash, but no data, also read
file, generate hash and then discard it (free buffer).
Index: drafts.c
===================================================================
RCS file: /home/cvs/ekg2/plugins/jogger/drafts.c,v
diff -d -u -r1.16 -r1.17
--- drafts.c 6 May 2007 22:54:35 -0000 1.16
+++ drafts.c 7 May 2007 08:23:00 -0000 1.17
@@ -99,9 +99,10 @@
}
/**
- * ekg_openfile()
+ * ekg_checkoutfile()
*
- * Tries to open given file, and reads it, if expected.
+ * Tries to open given file (check), and reads it, if expected (checkout).
+ * It is designed to be proof to special file problems (especially named pipe ones).
*
* @param fn - filename to open.
* @param data - pointer to store file contents or NULL, if don't want to read it.
@@ -110,7 +111,7 @@
*
* @return 0 on success, errno on failure.
*/
-static int ekg_openfile(const char *fn, char **data, int *len, char **hash, const int maxlen, const int quiet) {
+static int ekg_checkoutfile(const char *fn, char **data, int *len, char **hash, const int maxlen, const int quiet) {
static char jogger_hash[sizeof(int)*2+3];
int mylen, fs, fd;
@@ -145,7 +146,7 @@
}
}
- if (data) {
+ if (data || hash) {
char *out = xmalloc(fs+1);
void *p = out;
int rem = fs, res = 1;
@@ -193,7 +194,10 @@
snprintf(jogger_hash, sizeof(int)*2+3, sizecont, ekg_hash(out));
*hash = jogger_hash;
}
- *data = out;
+ if (data)
+ *data = out;
+ else
+ xfree(out);
} else if (len)
*len = fs;
close(fd);
@@ -215,7 +219,7 @@
return -1;
}
- if (ekg_openfile(prepare_path_user(fn), &entry, NULL, &hash, 0, quiet))
+ if (ekg_checkoutfile(prepare_path_user(fn), &entry, NULL, &hash, 0, quiet))
return -1;
len = xstrlen(entry);
s = entry;
@@ -351,7 +355,7 @@
return -1;
}
- if (ekg_openfile(prepare_path_user(fn), &entry, NULL, &hash, 0, quiet))
+ if (ekg_checkoutfile(prepare_path_user(fn), &entry, NULL, &hash, 0, quiet))
return -1;
if (oldhash && xstrcmp(oldhash, hash)) {
print("jogger_hashdiffers");
Więcej informacji o liście dyskusyjnej ekg2-commit