aboutsummaryrefslogtreecommitdiffstats
path: root/libibex
diff options
context:
space:
mode:
authorNotZed <NotZed@HelixCode.com>2000-03-28 08:39:36 +0800
committerMichael Zucci <zucchi@src.gnome.org>2000-03-28 08:39:36 +0800
commit03bcc319cfa2f92e86da72d0bd9f6040f4800aa0 (patch)
treeb7d65a7a51f8261228c4e9cb31eb1b10014c2779 /libibex
parent9eec5a12db8b2e53fc1e346478e320fd6efb2a70 (diff)
downloadgsoc2013-evolution-03bcc319cfa2f92e86da72d0bd9f6040f4800aa0.tar.gz
gsoc2013-evolution-03bcc319cfa2f92e86da72d0bd9f6040f4800aa0.tar.zst
gsoc2013-evolution-03bcc319cfa2f92e86da72d0bd9f6040f4800aa0.zip
Fixed call to ibex_open.
2000-03-26 NotZed <NotZed@HelixCode.com> * lookup.c (main): Fixed call to ibex_open. * mkindex.c (main): Fixed call to ibex_open. * file.c (ibex_open): Changed to accept flags and mode equivalent to open(2). svn path=/trunk/; revision=2202
Diffstat (limited to 'libibex')
-rw-r--r--libibex/ChangeLog9
-rw-r--r--libibex/file.c55
-rw-r--r--libibex/ibex.h4
-rw-r--r--libibex/lookup.c2
-rw-r--r--libibex/mkindex.c2
5 files changed, 61 insertions, 11 deletions
diff --git a/libibex/ChangeLog b/libibex/ChangeLog
index ba785db21a..ef27870817 100644
--- a/libibex/ChangeLog
+++ b/libibex/ChangeLog
@@ -1,3 +1,12 @@
+2000-03-26 NotZed <NotZed@HelixCode.com>
+
+ * lookup.c (main): Fixed call to ibex_open.
+
+ * mkindex.c (main): Fixed call to ibex_open.
+
+ * file.c (ibex_open): Changed to accept flags and mode equivalent
+ to open(2).
+
2000-02-25 Dan Winship <danw@helixcode.com>
* *.c: add gtk-doc-style comments
diff --git a/libibex/file.c b/libibex/file.c
index 0cf637764e..f011312cab 100644
--- a/libibex/file.c
+++ b/libibex/file.c
@@ -56,14 +56,17 @@ static void free_word (gpointer key, gpointer value, gpointer data);
/**
* ibex_open: open (or possibly create) an ibex index
* @file: the name of the file
- * @create: whether or not to create the file if it doesn't exist.
+ * @flags: open flags, see open(2).
+ * @mode: If O_CREAT is passed in flags, then the file mode
+ * to create the new file with. It will be anded with the current
+ * umask.
*
* Open and/or create the named ibex file and return a handle to it.
*
* Return value: an ibex handle, or NULL if an error occurred.
**/
ibex *
-ibex_open (char *file, gboolean create)
+ibex_open (char *file, int flags, int mode)
{
ibex *ib;
FILE *f;
@@ -73,9 +76,44 @@ ibex_open (char *file, gboolean create)
ibex_file **ibfs = NULL;
int i;
GPtrArray *refs;
+ int fd;
+ char *modestr;
- f = fopen (file, "r");
- if (!f && (errno != ENOENT || !create)) {
+ fd = open(file, flags, mode);
+ if (fd == -1) {
+ printf("open failed :(\n");
+ return NULL;
+ }
+
+ /* yuck, this is because we use FILE * interface
+ internally */
+ switch (flags & O_ACCMODE) {
+ case O_RDONLY:
+ modestr = "r";
+ break;
+ case O_RDWR:
+ if (flags & O_APPEND)
+ modestr = "a+";
+ else
+ modestr = "w+";
+ break;
+ case O_WRONLY:
+ if (flags & O_APPEND)
+ modestr = "a";
+ else
+ modestr = "w";
+ break;
+ default:
+ if (flags & O_APPEND)
+ modestr = "a+";
+ else
+ modestr = "r+";
+ break;
+ }
+
+ f = fdopen(fd, modestr);
+ if (f == NULL) {
+ printf("fdopen failed, modestr = '%s'\n", modestr);
if (errno == 0)
errno = ENOMEM;
return NULL;
@@ -91,11 +129,11 @@ ibex_open (char *file, gboolean create)
if (!f)
return ib;
- /* Check version. */
+ /* Check version. If its empty, then we have just created it */
if (fread (vbuf, 1, sizeof (vbuf), f) != sizeof (vbuf)) {
- if (feof (f))
- errno = EINVAL;
- goto errout;
+ if (feof (f)) {
+ return ib;
+ }
}
if (strncmp (vbuf, IBEX_VERSION, sizeof (vbuf) != 0)) {
errno = EINVAL;
@@ -141,6 +179,7 @@ ibex_open (char *file, gboolean create)
return ib;
errout:
+
fclose (f);
g_tree_traverse (ib->files, free_file, G_IN_ORDER, NULL);
g_tree_destroy (ib->files);
diff --git a/libibex/ibex.h b/libibex/ibex.h
index b74db1ed93..bb818e6d34 100644
--- a/libibex/ibex.h
+++ b/libibex/ibex.h
@@ -22,6 +22,8 @@
#define IBEX_H
#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#include <glib.h>
struct ibex;
@@ -34,7 +36,7 @@ typedef struct ibex ibex;
/* Open the named ibex index file. If CREATE is true, create the file
* if it doesn't already exist.
*/
-ibex *ibex_open (char *file, gboolean create);
+ibex *ibex_open (char *file, int flags, int mode);
/* Write the ibex to disk. */
int ibex_write (ibex *ib);
diff --git a/libibex/lookup.c b/libibex/lookup.c
index aa09fc6557..2d01dbf850 100644
--- a/libibex/lookup.c
+++ b/libibex/lookup.c
@@ -61,7 +61,7 @@ main (int argc, char **argv)
if (argc == 0)
usage ();
- ib = ibex_open (file, FALSE);
+ ib = ibex_open (file, O_RDWR|O_CREAT, 0600);
if (!ib) {
printf ("Couldn't open %s: %s\n", file, strerror (errno));
exit (1);
diff --git a/libibex/mkindex.c b/libibex/mkindex.c
index 9d6841e90b..151dcecb2d 100644
--- a/libibex/mkindex.c
+++ b/libibex/mkindex.c
@@ -60,7 +60,7 @@ main (int argc, char **argv)
if (argc == 0)
usage ();
- ib = ibex_open (file, TRUE);
+ ib = ibex_open (file, O_CREAT|O_RDWR, 0600);
if (!ib) {
fprintf (stderr, "Couldn't open index file %s: %s\n",
file, strerror (errno));
:50 +0800'>2003-03-251-0/+9 * Clear moonlight beckons.ade2003-03-072-1/+1 * Fix logic error when NOPORTDOCS is set.obrien2002-09-291-2/+2 * Mirror the patch files.obrien2002-09-201-1/+3 * Use offical vendor patches 1-4.obrien2002-09-133-20/+9 * Use the offical vendor patch for the directory space vs. slash command nameobrien2002-09-103-26/+4 * Bump revision for directory command-line completion fix.obrien2002-09-091-0/+1 * "In certain cases, Bash appends a space instead of a slash to a directory nameobrien2002-09-091-8/+34 * We lie about fully having ISO C90 Amd.1 restartable wide and multibyteobrien2002-08-262-0/+26 * Simply typing Shift-Enter in bash-2.05b causes it to enter some kind ofobrien2002-08-061-0/+16 * `make reinstall' clean.obrien2002-08-061-1/+1 * Forgot to update pkg-plist with 5.0b upgrade.obrien2002-08-051-2/+3 * Update to version 2.05b.obrien2002-08-046-58/+38 * No longer need to explicitly provide a GNU autconf target.obrien2002-03-281-1/+0 * Make FINGORE gain a brain. If NO_FORCE_FIGNORE is set, and a file in theobrien2002-03-251-0/+118 * Use ${ECHO_CMD} instead of ${ECHO} where you mean the echo command;knu2002-01-291-1/+1 * Override CONFIGURE_TARGET, so that this configure script generated bysobomax2001-11-231-0/+1 * * Update to 2.05a.naddy2001-11-2113-206/+189 * Our `end' key defintion for TERM==cons25 seems to be different from others.obrien2001-04-121-0/+14 * Remove. Patch not needed any longer.obrien2001-04-101-0/+0 * Update to version 2.05.obrien2001-04-105-27/+11 * Fix a segmentation fault on the Alpha.obrien2001-03-171-0/+20 * Put back my editor hints that were removed w/o permission.obrien2001-02-071-0/+1 * Massive style enforcement - use ^I instead of spaces for variables identation.sobomax2001-01-171-4/+3 * Fix typoobrien2000-12-231-1/+1 * It's my main shell, so I have in interest in seeing it maintained.obrien2000-11-301-1/+2 * Drop my maintainershipache2000-11-301-1/+1 * Re-add patch for failglob variable (see previous discussion on -commiters)cracauer2000-05-241-0/+151 * Fix trace() symbol clash with ncursescracauer2000-05-24