]> mj.ucw.cz Git - libucw.git/commitdiff
Added bopen_tmp() for opening of temporary files.
authorMartin Mares <mj@ucw.cz>
Sun, 26 May 2002 10:40:52 +0000 (10:40 +0000)
committerMartin Mares <mj@ucw.cz>
Sun, 26 May 2002 10:40:52 +0000 (10:40 +0000)
Replaced sorter_open_tmp() by bopen_tmp().

lib/Makefile
lib/fastbuf.h
lib/fb-temp.c [new file with mode: 0644]
lib/sorter.c
lib/sorter.h

index 2d96bb1d90bc6aea1928b80121c9efe214ddd3b6..70853050d4b3a315e106f5421d79f78950b780ca 100644 (file)
@@ -8,7 +8,7 @@ SHLIB_OBJS=alloc.o alloc_str.o ctmatch.o db.o fastbuf.o fb-file.o fb-mem.o lists
        prime.o random.o realloc.o regex.o timer.o url.o wildmatch.o \
        wordsplit.o str_ctype.o str_upper.o bucket.o conf.o object.o sorter.o \
        finger.o proctitle.o ipaccess.o profile.o bitsig.o randomkey.o \
-       hash-string.o hash-istring.o custom.o base224.o str_hash.o
+       hash-string.o hash-istring.o custom.o base224.o str_hash.o fb-temp.o
 
 obj/lib/libsh.a: $(addprefix obj/lib/,$(SHLIB_OBJS))
 
index c6e6e333d4ebd288440cf9a803ab4d54afbf8760..2948830ee4e0331e305a9c5a9ceb66486ca738db 100644 (file)
@@ -59,6 +59,7 @@ struct fastbuf {
 /* FastIO on standard files */
 
 struct fastbuf *bopen(byte *name, uns mode, uns buffer);
+struct fastbuf *bopen_tmp(uns buffer);
 struct fastbuf *bfdopen(int fd, uns buffer);
 void bbcopy(struct fastbuf *f, struct fastbuf *t, uns l);
 
diff --git a/lib/fb-temp.c b/lib/fb-temp.c
new file mode 100644 (file)
index 0000000..95edf16
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ *     Sherlock Library -- Temporary Fastbufs
+ *
+ *     (c) 2002 Martin Mares <mj@ucw.cz>
+ */
+
+#include "lib/lib.h"
+#include "lib/conf.h"
+#include "lib/fastbuf.h"
+
+#include <unistd.h>
+#include <sys/fcntl.h>
+
+static byte *temp_template = "/tmp/temp%d.%d";
+
+static struct cfitem temp_config[] = {
+  { "Tempfiles",       CT_SECTION,     NULL },
+  { "Template",                CT_STRING,      &temp_template },
+  { NULL,              CT_STOP,        NULL }
+};
+
+static void CONSTRUCTOR temp_init_config(void)
+{
+  cf_register(temp_config);
+}
+
+struct fastbuf *
+bopen_tmp(uns bufsize)
+{
+  byte buf[256];
+  struct fastbuf *f;
+  static uns temp_counter;
+
+  sprintf(buf, temp_template, (int) getpid(), temp_counter++);
+  f = bopen(buf, O_RDWR | O_CREAT | O_EXCL, bufsize);
+  f->is_temp_file = 1;
+  return f;
+}
index b43672f4b99d10e090a4450e9338fe69c233ea46..328c671b021af69941841a67c2510fc1d0442386 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     Sherlock Library -- Universal Sorter
  *
- *     (c) 2001 Martin Mares <mj@ucw.cz>
+ *     (c) 2001--2002 Martin Mares <mj@ucw.cz>
  */
 
 #include "lib/lib.h"
 uns sorter_trace;
 uns sorter_presort_bufsize = 65536;
 uns sorter_stream_bufsize = 65536;
-static byte *sorter_template = "/tmp/sort%d.%d";
 
 static struct cfitem sorter_config[] = {
   { "Sorter",          CT_SECTION,     NULL },
   { "Trace",           CT_INT,         &sorter_trace },
   { "PresortBuffer",   CT_INT,         &sorter_presort_bufsize },
   { "StreamBuffer",    CT_INT,         &sorter_stream_bufsize },
-  { "TempLate",                CT_STRING,      &sorter_template },
   { NULL,              CT_STOP,        NULL }
 };
 
@@ -34,16 +32,3 @@ static void CONSTRUCTOR sorter_init_config(void)
 }
 
 uns sorter_pass_counter;
-uns sorter_file_counter;
-
-struct fastbuf *
-sorter_open_tmp(void)
-{
-  byte buf[256];
-  struct fastbuf *f;
-
-  sprintf(buf, sorter_template, (int) getpid(), sorter_file_counter++);
-  f = bopen(buf, O_RDWR | O_CREAT | O_EXCL, sorter_stream_bufsize);
-  f->is_temp_file = 1;
-  return f;
-}
index d1f059fccec58f0240748dc7dc0777cb78eaa27d..bf0e5b962ab937fb0b291f968383b4557aec7d1d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     Sherlock Library -- Universal Sorter
  *
- *     (c) 2001 Martin Mares <mj@ucw.cz>
+ *     (c) 2001--2002 Martin Mares <mj@ucw.cz>
  */
 
 /*
@@ -75,8 +75,7 @@ extern uns sorter_trace;
 extern uns sorter_presort_bufsize;
 extern uns sorter_stream_bufsize;
 
-extern uns sorter_pass_counter, sorter_file_counter;
-struct fastbuf *sorter_open_tmp(void);
+extern uns sorter_pass_counter;
 
 #endif         /* !SORT_DECLS_READ */
 
@@ -147,7 +146,7 @@ P(pass)(struct fastbuf **fb1, struct fastbuf **fb2)
          struct fastbuf *t;
          SWAP(out1, out2, t);
          if (!out1)
-           out1 = sorter_open_tmp();
+           out1 = bopen_tmp(sorter_stream_bufsize);
          run_count++;
        }
       if (comp LESS 0)
@@ -273,7 +272,7 @@ P(presort)(struct fastbuf **fb1, struct fastbuf **fb2)
     {
       SWAP(out1, out2, tbuf);
       if (!out1)
-       out1 = sorter_open_tmp();
+       out1 = bopen_tmp(sorter_stream_bufsize);
       current = buffer;
       last = &first;
       if (leftover)
@@ -391,7 +390,7 @@ struct fastbuf *fb1, struct fastbuf *fb2
 #endif
     do P(pass)(&fb1, &fb2); while (fb1 && fb2);
   if (!fb1)
-    fb1 = sorter_open_tmp();
+    fb1 = bopen_tmp(sorter_stream_bufsize);
 
 #ifdef SORT_OUTPUT_FB
   return fb1;