From: Martin Mares Date: Sun, 26 May 2002 10:40:52 +0000 (+0000) Subject: Added bopen_tmp() for opening of temporary files. X-Git-Tag: holmes-import~1423 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=8299c27047b1a992e2b38463421ec4a4a69f8cec;p=libucw.git Added bopen_tmp() for opening of temporary files. Replaced sorter_open_tmp() by bopen_tmp(). --- diff --git a/lib/Makefile b/lib/Makefile index 2d96bb1d..70853050 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -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)) diff --git a/lib/fastbuf.h b/lib/fastbuf.h index c6e6e333..2948830e 100644 --- a/lib/fastbuf.h +++ b/lib/fastbuf.h @@ -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 index 00000000..95edf166 --- /dev/null +++ b/lib/fb-temp.c @@ -0,0 +1,38 @@ +/* + * Sherlock Library -- Temporary Fastbufs + * + * (c) 2002 Martin Mares + */ + +#include "lib/lib.h" +#include "lib/conf.h" +#include "lib/fastbuf.h" + +#include +#include + +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; +} diff --git a/lib/sorter.c b/lib/sorter.c index b43672f4..328c671b 100644 --- a/lib/sorter.c +++ b/lib/sorter.c @@ -1,7 +1,7 @@ /* * Sherlock Library -- Universal Sorter * - * (c) 2001 Martin Mares + * (c) 2001--2002 Martin Mares */ #include "lib/lib.h" @@ -17,14 +17,12 @@ 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; -} diff --git a/lib/sorter.h b/lib/sorter.h index d1f059fc..bf0e5b96 100644 --- a/lib/sorter.h +++ b/lib/sorter.h @@ -1,7 +1,7 @@ /* * Sherlock Library -- Universal Sorter * - * (c) 2001 Martin Mares + * (c) 2001--2002 Martin Mares */ /* @@ -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;