add io_readwritefile, io_appendfile
This commit is contained in:
parent
11f0616cf3
commit
696c5f872c
1
CHANGES
1
CHANGES
@ -1,6 +1,7 @@
|
||||
0.20:
|
||||
add errmsg API
|
||||
work around broken Linux sendfile API (offset 64-bit but count 32-bit)
|
||||
add io_appendfile, io_readwritefile
|
||||
|
||||
0.19.2:
|
||||
for some reason, a botched dependency slipped in the the Makefile
|
||||
|
8
Makefile
8
Makefile
@ -162,6 +162,9 @@ fmt_ulong0.o: fmt/fmt_ulong0.c ./fmt.h
|
||||
fmt_ulonglong.o: fmt/fmt_ulonglong.c ./fmt.h
|
||||
fmt_xlong.o: fmt/fmt_xlong.c ./fmt.h ./haveinline.h
|
||||
fmt_xlonglong.o: fmt/fmt_xlonglong.c ./fmt.h
|
||||
io_appendfile.o: io/io_appendfile.c ./io_internal.h ./io.h ./uint64.h \
|
||||
./taia.h ./tai.h ./array.h ./haveepoll.h ./havekqueue.h ./havedevpoll.h \
|
||||
./havesigio.h
|
||||
io_canread.o: io/io_canread.c ./io_internal.h ./io.h ./uint64.h ./taia.h \
|
||||
./tai.h ./array.h ./haveepoll.h ./havekqueue.h ./havedevpoll.h \
|
||||
./havesigio.h
|
||||
@ -210,6 +213,9 @@ io_pipe.o: io/io_pipe.c ./io_internal.h ./io.h ./uint64.h ./taia.h \
|
||||
io_readfile.o: io/io_readfile.c ./io_internal.h ./io.h ./uint64.h \
|
||||
./taia.h ./tai.h ./array.h ./haveepoll.h ./havekqueue.h ./havedevpoll.h \
|
||||
./havesigio.h
|
||||
io_readwritefile.o: io/io_readwritefile.c ./io_internal.h ./io.h \
|
||||
./uint64.h ./taia.h ./tai.h ./array.h ./haveepoll.h ./havekqueue.h \
|
||||
./havedevpoll.h ./havesigio.h
|
||||
io_receivefd.o: io/io_receivefd.c ./io_internal.h ./io.h ./uint64.h \
|
||||
./taia.h ./tai.h ./array.h ./haveepoll.h ./havekqueue.h ./havedevpoll.h \
|
||||
./havesigio.h
|
||||
@ -584,7 +590,7 @@ DNS_OBJS=dns_dfd.o dns_domain.o dns_dtda.o dns_ip.o dns_ip6.o dns_ipq.o dns_ipq6
|
||||
CASE_OBJS=case_diffb.o case_diffs.o case_lowerb.o case_lowers.o case_starts.o
|
||||
MULT_OBJS=imult16.o imult32.o imult64.o umult16.o umult32.o umult64.o
|
||||
ARRAY_OBJS=array_allocate.o array_bytes.o array_cat.o array_cat0.o array_catb.o array_cate.o array_cats.o array_cats0.o array_equal.o array_fail.o array_get.o array_length.o array_reset.o array_start.o array_trunc.o array_truncate.o
|
||||
IO_OBJS=io_canread.o io_canwrite.o io_check.o io_close.o io_closeonexec.o io_createfile.o io_dontwantread.o io_dontwantwrite.o io_eagain.o io_fd.o io_finishandshutdown.o io_getcookie.o io_nonblock.o io_passfd.o io_pipe.o io_readfile.o io_receivefd.o io_sendfile.o io_setcookie.o io_sigpipe.o io_socketpair.o io_timeout.o io_timeouted.o io_tryread.o io_tryreadtimeout.o io_trywrite.o io_trywritetimeout.o io_wait.o io_waitread.o io_waituntil.o io_waituntil2.o io_waitwrite.o io_wantread.o io_wantwrite.o iob_addbuf.o iob_addbuf_free.o iob_addbuf_internal.o iob_addfile.o iob_addfile_close.o iob_adds.o iob_adds_free.o iob_new.o iob_prefetch.o iob_reset.o iob_send.o
|
||||
IO_OBJS=io_appendfile.o io_canread.o io_canwrite.o io_check.o io_close.o io_closeonexec.o io_createfile.o io_dontwantread.o io_dontwantwrite.o io_eagain.o io_fd.o io_finishandshutdown.o io_getcookie.o io_nonblock.o io_passfd.o io_pipe.o io_readfile.o io_readwritefile.o io_receivefd.o io_sendfile.o io_setcookie.o io_sigpipe.o io_socketpair.o io_timeout.o io_timeouted.o io_tryread.o io_tryreadtimeout.o io_trywrite.o io_trywritetimeout.o io_wait.o io_waitread.o io_waituntil.o io_waituntil2.o io_waitwrite.o io_wantread.o io_wantwrite.o iob_addbuf.o iob_addbuf_free.o iob_addbuf_internal.o iob_addfile.o iob_addfile_close.o iob_adds.o iob_adds_free.o iob_new.o iob_prefetch.o iob_reset.o iob_send.o
|
||||
TEXTCODE_OBJS=base64.o fmt_base64.o fmt_cescape.o fmt_foldwhitespace.o fmt_hexdump.o fmt_html.o fmt_quotedprintable.o fmt_to_array.o fmt_to_sa.o fmt_tofrom_array.o fmt_urlencoded.o fmt_uuencoded.o fmt_yenc.o scan_base64.o scan_cescape.o scan_hexdump.o scan_html.o scan_quotedprintable.o scan_to_array.o scan_to_sa.o scan_tofrom_array.o scan_urlencoded.o scan_uuencoded.o scan_yenc.o
|
||||
|
||||
byte.a: $(BYTE_OBJS)
|
||||
|
6
io.h
6
io.h
@ -12,6 +12,12 @@ int io_readfile(int64* d,const char* s);
|
||||
/* like open(s,O_WRONLY|O_CREAT|O_TRUNC,0600) */
|
||||
/* return 1 if ok, 0 on error */
|
||||
int io_createfile(int64* d,const char* s);
|
||||
/* like open(s,O_RDWR) */
|
||||
/* return 1 if ok, 0 on error */
|
||||
int io_readwritefile(int64* d,const char* s);
|
||||
/* like open(s,O_WRONLY|O_APPEND|O_CREAT,0600) */
|
||||
/* return 1 if ok, 0 on error */
|
||||
int io_appendfile(int64* d,const char* s);
|
||||
/* like pipe(d) */
|
||||
/* return 1 if ok, 0 on error */
|
||||
int io_pipe(int64* d);
|
||||
|
16
io/io_appendfile.3
Normal file
16
io/io_appendfile.3
Normal file
@ -0,0 +1,16 @@
|
||||
.TH io_appendfile 3
|
||||
.SH NAME
|
||||
io_appendfile \- open a file for appending
|
||||
.SH SYNTAX
|
||||
.B #include <io.h>
|
||||
|
||||
int \fBio_appendfile\fP(int64* d,const char* s);
|
||||
.SH DESCRIPTION
|
||||
io_appendfile sets d to the number of a new descriptor writing to the
|
||||
end of the disk file named \fIs\fR, and returns 1. If the file does not
|
||||
exist, it will be created with mode 0600.
|
||||
|
||||
If something goes wrong, io_appendfile sets \fIerrno\fR to indicate the error, and
|
||||
returns 0; it does not create a new descriptor, and it does not touch d.
|
||||
.SH "SEE ALSO"
|
||||
io_readfile(3), io_createfile(3), io_readwritefile(3)
|
13
io/io_appendfile.c
Normal file
13
io/io_appendfile.c
Normal file
@ -0,0 +1,13 @@
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include "io_internal.h"
|
||||
|
||||
int io_appendfile(int64* d,const char* s) {
|
||||
long fd=open(s,O_WRONLY|O_APPEND|O_CREAT,0600);
|
||||
if (fd != -1) {
|
||||
*d=fd;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -14,4 +14,4 @@ If something goes wrong, io_createfile sets \fIerrno\fR to indicate the error, a
|
||||
returns 0; it does not create a new descriptor, and it does not touch d.
|
||||
(However, it may have truncated or created the file.)
|
||||
.SH "SEE ALSO"
|
||||
io_readfile(3)
|
||||
io_readfile(3), io_appendfile(3), io_readwritefile(3)
|
||||
|
@ -12,4 +12,4 @@ disk file named \fIs\fR, and returns 1.
|
||||
If something goes wrong, io_readfile sets \fIerrno\fR to indicate the error, and
|
||||
returns 0; it does not create a new descriptor, and it does not touch d.
|
||||
.SH "SEE ALSO"
|
||||
io_readfile(3)
|
||||
io_createfilefile(3), io_appendfile(3), io_readwritefile(3)
|
||||
|
16
io/io_readwritefile.3
Normal file
16
io/io_readwritefile.3
Normal file
@ -0,0 +1,16 @@
|
||||
.TH io_readwritefile 3
|
||||
.SH NAME
|
||||
io_readfile \- open a file for reading and writing
|
||||
.SH SYNTAX
|
||||
.B #include <io.h>
|
||||
|
||||
int \fBio_readwritefile\fP(int64* d,const char* s);
|
||||
.SH DESCRIPTION
|
||||
io_readwritefile sets d to the number of a new descriptor reading from
|
||||
and writing to the disk file named \fIs\fR, and returns 1. The file
|
||||
needs to exist.
|
||||
|
||||
If something goes wrong, io_readwritefile sets \fIerrno\fR to indicate the error, and
|
||||
returns 0; it does not create a new descriptor, and it does not touch d.
|
||||
.SH "SEE ALSO"
|
||||
io_readfile(3), io_createfile(3), io_appendfile(3)
|
13
io/io_readwritefile.c
Normal file
13
io/io_readwritefile.c
Normal file
@ -0,0 +1,13 @@
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include "io_internal.h"
|
||||
|
||||
int io_readwritefile(int64* d,const char* s) {
|
||||
long fd=open(s,O_RDWR);
|
||||
if (fd != -1) {
|
||||
*d=fd;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user