소스 검색

add buffer_putm and buffer_putmflush

master
Felix von Leitner 16 년 전
부모
커밋
e3b165e9e8
28개의 변경된 파일157개의 추가작업 그리고 10개의 파일을 삭제
  1. +2
    -0
      CHANGES
  2. +5
    -0
      buffer.h
  3. +2
    -3
      buffer/buffer_getline.3
  4. +3
    -3
      buffer/buffer_put.3
  5. +2
    -0
      buffer/buffer_put8long.3
  6. +2
    -0
      buffer/buffer_putalign.3
  7. +2
    -0
      buffer/buffer_puterror.3
  8. +2
    -0
      buffer/buffer_puterror2.3
  9. +2
    -0
      buffer/buffer_putflush.3
  10. +2
    -0
      buffer/buffer_putlong.3
  11. +2
    -0
      buffer/buffer_putlonglong.3
  12. +15
    -0
      buffer/buffer_putm.3
  13. +16
    -0
      buffer/buffer_putm_internal.c
  14. +17
    -0
      buffer/buffer_putm_internal_flush.c
  15. +2
    -0
      buffer/buffer_putnlflush.3
  16. +3
    -0
      buffer/buffer_puts.3
  17. +2
    -1
      buffer/buffer_putsa.3
  18. +2
    -1
      buffer/buffer_putsaflush.3
  19. +2
    -0
      buffer/buffer_putsalign.3
  20. +2
    -0
      buffer/buffer_putspace.3
  21. +2
    -0
      buffer/buffer_putulong.3
  22. +2
    -0
      buffer/buffer_putulonglong.3
  23. +2
    -0
      buffer/buffer_putxlong.3
  24. +8
    -2
      stralloc.h
  25. +17
    -0
      stralloc/stralloc_catm.3
  26. +15
    -0
      stralloc/stralloc_catm_internal.c
  27. +16
    -0
      stralloc/stralloc_copym.3
  28. +8
    -0
      t.c

+ 2
- 0
CHANGES 파일 보기

@@ -5,6 +5,8 @@
stralloc first.
add stralloc_zero to clear a stralloc
add buffer_putsflush
add stralloc_catm and stralloc_copym
add buffer_putm and buffer_putmflush

0.20:
add errmsg API


+ 5
- 0
buffer.h 파일 보기

@@ -25,6 +25,11 @@ int buffer_puts(buffer* b,const char* x);
int buffer_putsalign(buffer* b,const char* x);
int buffer_putsflush(buffer* b,const char* x);

int buffer_putm_internal(buffer*b,...);
int buffer_putm_internal_flush(buffer*b,...);
#define buffer_putm(b,...) buffer_putm_internal(b,__VA_ARGS__,0)
#define buffer_putmflush(b,...) buffer_putm_internal_flush(b,__VA_ARGS__,0)

int buffer_putspace(buffer* b);
int buffer_putnlflush(buffer* b); /* put \n and flush */



+ 2
- 3
buffer/buffer_getline.3 파일 보기

@@ -11,10 +11,9 @@ buffer_getline copies data from \fIb\fR to \fIx\fR[0], \fIx\fR[1], ...,
new-line character ('\\n') is encountered. That character is also
copied.

buffer_getline returns the number of bytes read (excluding the '\\n') or
-1 on error (setting \fIerrno\fR appropriately).

Note that line is not 0-terminated to make reading lines with 0-bytes
possible through this interface.
.SH "RETURN VALUE"
Number of bytes read (without '\\n'), -1 on error (setting \fIerrno\fR).
.SH "SEE ALSO"
buffer_init(3), buffer_feed(3), buffer_peek(3), buffer_seek(3), buffer(3)

+ 3
- 3
buffer/buffer_put.3 파일 보기

@@ -12,8 +12,8 @@ The difference to buffer_putalign is that, when there isn't enough space
for new data, buffer_put calls buffer_flush before copying any data,
while buffer_putalign fills all available space with data before calling
buffer_flush.
On success, buffer_put returns 0. On error, buffer_put returns -1,
setting \fIerrno\fR appropriately.
.SH "RETURN VALUE"
buffer_put returns 0 if everything was fine, -1 on error (setting
errno).
.SH "SEE ALSO"
buffer_putalign(3), buffer_puts(3), buffer_flush(3), buffer(3)

+ 2
- 0
buffer/buffer_put8long.3 파일 보기

@@ -9,5 +9,7 @@ int \fBbuffer_put8long\fP(buffer* \fIb\fR,unsigned long \fIx\fR);
.SH DESCRIPTION
buffer_put8long is similar to passing the result of fmt_8long to
buffer_put.
.SH "RETURN VALUE"
0 if everything is fine, -1 on error (setting \fIerrno\fR).
.SH "SEE ALSO"
fmt_8long(3), buffer_put(3), buffer_flush(3), buffer(3)

+ 2
- 0
buffer/buffer_putalign.3 파일 보기

@@ -12,5 +12,7 @@ The difference to buffer_put is that, when there isn't enough space for
new data, buffer_put calls buffer_flush before copying any data, while
buffer_putalign fills all available space with data before calling
buffer_flush.
.SH "RETURN VALUE"
0 if everything is fine, -1 on error (setting \fIerrno\fR).
.SH "SEE ALSO"
buffer_put(3), buffer_putsalign(3), buffer_flush(3), buffer(3)

+ 2
- 0
buffer/buffer_puterror.3 파일 보기

@@ -7,5 +7,7 @@ buffer_puterror \- write error string to buffer and flush
int \fBbuffer_puterror\fP(buffer* \fIb\fR);
.SH DESCRIPTION
buffer_puterror is equivalent to calling buffer_puterror2 with errno.
.SH "RETURN VALUE"
0 if everything is fine, -1 on error (setting \fIerrno\fR).
.SH "SEE ALSO"
buffer_puterror2(3), buffer_puts(3), buffer_put(3), buffer_flush(3), buffer(3)

+ 2
- 0
buffer/buffer_puterror2.3 파일 보기

@@ -9,5 +9,7 @@ int \fBbuffer_puterror2\fP(buffer* \fIb\fR,int \fIerrnum\fR);
buffer_puterror2 writes the error message corresponding to the error
number in \fIerrnum\fR to the buffer (e.g. "No such file or directory"
for ENOENT).
.SH "RETURN VALUE"
0 if everything is fine, -1 on error (setting \fIerrno\fR).
.SH "SEE ALSO"
buffer_puterror(3), buffer_puts(3), buffer_put(3), buffer_flush(3), buffer(3)

+ 2
- 0
buffer/buffer_putflush.3 파일 보기

@@ -9,5 +9,7 @@ int \fBbuffer_putflush\fP(buffer* \fIb\fR,
.SH DESCRIPTION
buffer_putflush is similar to calling
buffer_put(\fIb\fR,\fIx\fR,\fIlen\fR) and then buffer_flush(\fIb\fR).
.SH "RETURN VALUE"
0 if everything is fine, -1 on error (setting \fIerrno\fR).
.SH "SEE ALSO"
buffer_put(3), buffer_flush(3), buffer(3)

+ 2
- 0
buffer/buffer_putlong.3 파일 보기

@@ -9,5 +9,7 @@ int \fBbuffer_putlong\fP(buffer* \fIb\fR,signed long \fIx\fR);
.SH DESCRIPTION
buffer_putlong is similar to passing the result of fmt_long to
buffer_put.
.SH "RETURN VALUE"
0 if everything is fine, -1 on error (setting \fIerrno\fR).
.SH "SEE ALSO"
fmt_long(3), buffer_put(3), buffer_flush(3), buffer(3)

+ 2
- 0
buffer/buffer_putlonglong.3 파일 보기

@@ -9,5 +9,7 @@ int \fBbuffer_putlonglong\fP(buffer* \fIb\fR,signed long long \fIx\fR);
.SH DESCRIPTION
buffer_putlonglong is equivalent to passing the result of fmt_longlong to
buffer_put.
.SH "RETURN VALUE"
0 if everything is fine, -1 on error (setting \fIerrno\fR).
.SH "SEE ALSO"
fmt_longlong(3), buffer_put(3), buffer_flush(3), buffer(3)

+ 15
- 0
buffer/buffer_putm.3 파일 보기

@@ -0,0 +1,15 @@
.TH buffer_putm 3
.SH NAME
buffer_putm \- write ASCIIZ string(s) to buffer
.SH SYNTAX
.B #include <buffer.h>

int \fBbuffer_putm\fP(buffer* \fIb\fR,const char* \fIx\fR,...);
.SH DESCRIPTION
buffer_putm is like buffer_puts, but it can be passed more than one
string.
.SH "RETURN VALUE"
buffer_putm returns 0 if everything was fine, -1 on error (setting
errno).
.SH "SEE ALSO"
buffer_putsalign(3), buffer_put(3), buffer_flush(3), buffer(3)

+ 16
- 0
buffer/buffer_putm_internal.c 파일 보기

@@ -0,0 +1,16 @@
#include <stdarg.h>
#include "buffer.h"

int buffer_putm_internal(buffer* b, ...) {
int r=0;
va_list a;
const char* s;
va_start(a,b);
while ((s=va_arg(a,const char*)))
if (buffer_puts(b,s)==-1) {
r=-1;
break;
}
va_end(a);
return r;
}

+ 17
- 0
buffer/buffer_putm_internal_flush.c 파일 보기

@@ -0,0 +1,17 @@
#include <stdarg.h>
#include "buffer.h"

int buffer_putm_internal_flush(buffer* b, ...) {
int r=0;
va_list a;
const char* s;
va_start(a,b);
while ((s=va_arg(a,const char*)))
if (buffer_puts(b,s)==-1) {
r=-1;
break;
}
va_end(a);
buffer_flush(b);
return r;
}

+ 2
- 0
buffer/buffer_putnlflush.3 파일 보기

@@ -8,5 +8,7 @@ int \fBbuffer_putnlflush\fP(buffer* \fIb\fR);
.SH DESCRIPTION
buffer_putnlflush writes a single ASCII new-line character ('\\n') to
\fIb\fR and calls buffer_flush(\fIb\fR).
.SH "RETURN VALUE"
0 if everything is fine, -1 on error (setting \fIerrno\fR).
.SH "SEE ALSO"
buffer_puts(3), buffer_put(3), buffer_flush(3), buffer(3)

+ 3
- 0
buffer/buffer_puts.3 파일 보기

@@ -13,5 +13,8 @@ The difference to buffer_putsalign is that, when there isn't enough space
for new data, buffer_puts calls buffer_flush before copying any data,
while buffer_putsalign fills all available space with data before calling
buffer_flush.
.SH "RETURN VALUE"
buffer_puts returns 0 if everything was fine, -1 on error (setting
errno).
.SH "SEE ALSO"
buffer_putsalign(3), buffer_put(3), buffer_flush(3), buffer(3)

+ 2
- 1
buffer/buffer_putsa.3 파일 보기

@@ -9,6 +9,7 @@ buffer_putsa \- write stralloc to buffer
int \fBbuffer_putsa\fP(buffer* \fIb\fR,const char* \fIx\fR);
.SH DESCRIPTION
buffer_putsa is equivalent to buffer_put(b,x.sa,x.len).

.SH "RETURN VALUE"
0 if everything is fine, -1 on error (setting \fIerrno\fR).
.SH "SEE ALSO"
buffer_puts(3), buffer_flush(3), buffer(3)

+ 2
- 1
buffer/buffer_putsaflush.3 파일 보기

@@ -9,6 +9,7 @@ buffer_putsa \- write stralloc to buffer and flush
int \fBbuffer_putsaflush\fP(buffer* \fIb\fR,const char* \fIx\fR);
.SH DESCRIPTION
buffer_putsaflush is equivalent to buffer_putflush(b,x.sa,x.len).

.SH "RETURN VALUE"
0 if everything is fine, -1 on error (setting \fIerrno\fR).
.SH "SEE ALSO"
buffer_puts(3), buffer_flush(3), buffer(3)

+ 2
- 0
buffer/buffer_putsalign.3 파일 보기

@@ -8,5 +8,7 @@ int \fBbuffer_putsalign\fP(buffer* \fIb\fR,const char* \fIx\fR);
.SH DESCRIPTION
buffer_putsalign is like buffer_putalign with \fIlen\fR determined as
the number of bytes before the first \\0 in \fIx\fR.
.SH "RETURN VALUE"
0 if everything is fine, -1 on error (setting \fIerrno\fR).
.SH "SEE ALSO"
buffer_puts(3), buffer_put(3), buffer_flush(3), buffer(3)

+ 2
- 0
buffer/buffer_putspace.3 파일 보기

@@ -7,5 +7,7 @@ buffer_putspace \- write ASCII space to buffer
int \fBbuffer_putspace\fP(buffer* \fIb\fR);
.SH DESCRIPTION
buffer_putspace writes a single ASCII space character to \fIb\fR.
.SH "RETURN VALUE"
0 if everything is fine, -1 on error (setting \fIerrno\fR).
.SH "SEE ALSO"
buffer_puts(3), buffer_put(3), buffer_flush(3), buffer(3)

+ 2
- 0
buffer/buffer_putulong.3 파일 보기

@@ -9,5 +9,7 @@ int \fBbuffer_putulong\fP(buffer* \fIb\fR,unsigned long \fIx\fR);
.SH DESCRIPTION
buffer_putulong is similar to passing the result of fmt_ulong to
buffer_put.
.SH "RETURN VALUE"
0 if everything is fine, -1 on error (setting \fIerrno\fR).
.SH "SEE ALSO"
fmt_ulong(3), buffer_put(3), buffer_flush(3), buffer(3)

+ 2
- 0
buffer/buffer_putulonglong.3 파일 보기

@@ -9,5 +9,7 @@ int \fBbuffer_putulonglong\fP(buffer* \fIb\fR,unsigned long long \fIx\fR);
.SH DESCRIPTION
buffer_putulonglong is equivalent to passing the result of fmt_ulonglong to
buffer_put.
.SH "RETURN VALUE"
0 if everything is fine, -1 on error (setting \fIerrno\fR).
.SH "SEE ALSO"
fmt_ulonglong(3), buffer_put(3), buffer_flush(3), buffer(3)

+ 2
- 0
buffer/buffer_putxlong.3 파일 보기

@@ -9,5 +9,7 @@ int \fBbuffer_putxlong\fP(buffer* \fIb\fR,unsigned long \fIx\fR);
.SH DESCRIPTION
buffer_putxlong is similar to passing the result of fmt_xlong to
buffer_put.
.SH "RETURN VALUE"
0 if everything is fine, -1 on error (setting \fIerrno\fR).
.SH "SEE ALSO"
fmt_xlong(3), buffer_put(3), buffer_flush(3), buffer(3)

+ 8
- 2
stralloc.h 파일 보기

@@ -63,6 +63,14 @@ int stralloc_catb(stralloc* sa,const char* in,unsigned int len);
/* stralloc_cats is analogous to stralloc_copys */
int stralloc_cats(stralloc* sa,const char* in);

#define stralloc_zero(sa) stralloc_copys(sa,"")

/* like stralloc_cats but can cat more than one string at once */
int stralloc_catm_internal(stralloc* sa,...);

#define stralloc_catm(sa,...) stralloc_catm_internal(sa,__VA_ARGS__,0)
#define stralloc_copym(sa,...) (stralloc_zero(sa) && stralloc_catm_internal(sa,__VA_ARGS__,0))

/* stralloc_cat is analogous to stralloc_copy */
int stralloc_cat(stralloc* sa,stralloc* in);

@@ -91,8 +99,6 @@ int stralloc_diffs(const stralloc* a,const char* b) __pure__;
/* stralloc_0 appends \0 */
#define stralloc_0(sa) stralloc_append(sa,"")

#define stralloc_zero(sa) stralloc_copys(sa,"")

/* stralloc_catulong0 appends a '0' padded ASCII representation of in */
int stralloc_catulong0(stralloc* sa,unsigned long in,unsigned int n);



+ 17
- 0
stralloc/stralloc_catm.3 파일 보기

@@ -0,0 +1,17 @@
.TH stralloc_catm 3
.SH NAME
stralloc_catm \- append string(s) to a stralloc
.SH SYNTAX
.B #include <stralloc.h>

int \fBstralloc_cats\fP(stralloc* \fIsa\fR,const char* \fIs\fR, ...);
.SH DESCRIPTION
stralloc_cats appends \\0-terminated strings from \fIs\fR... to the
end of the string stored in \fIsa\fR, allocating space if necessary, and
returns 1. If \fIsa\fR is unallocated, stralloc_cats is the same as
stralloc_copys.

If it runs out of memory, stralloc_cats returns 0. At that point, it
may already have copied a few of the strings to sa.
.SH "SEE ALSO"
stralloc_cats(3)

+ 15
- 0
stralloc/stralloc_catm_internal.c 파일 보기

@@ -0,0 +1,15 @@
#include <stdarg.h>
#include "stralloc.h"

int stralloc_catm_internal(stralloc* sa, ...) {
va_list a;
const char* s;
va_start(a,sa);
while ((s=va_arg(a,const char*)))
if (stralloc_cats(sa,s)==0) {
va_end(a);
return 0;
}
va_end(a);
return 1;
}

+ 16
- 0
stralloc/stralloc_copym.3 파일 보기

@@ -0,0 +1,16 @@
.TH stralloc_catm 3
.SH NAME
stralloc_copym \- copy string(s) to a stralloc
.SH SYNTAX
.B #include <stralloc.h>

int \fBstralloc_copys\fP(stralloc* \fIsa\fR,const char* \fIs\fR, ...);
.SH DESCRIPTION
stralloc_cats copies \\0-terminated strings from \fIs\fR... to \fIsa\fR,
allocating space if necessary, and returns 1. If there is data in the
\fIsa\fR, it is cleared first.

If it runs out of memory, stralloc_copys returns 0. At that point, it
may already have copied a few of the strings to sa.
.SH "SEE ALSO"
stralloc_copys(3)

+ 8
- 0
t.c 파일 보기

@@ -25,11 +25,19 @@
__asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx")

int main(int argc,char* argv[]) {
#if 0
static stralloc sa;
stralloc_copym(&sa,"foo ","bar ","baz.\n");
write(1,sa.s,sa.len);
#endif
buffer_putmflush(buffer_1,"foo ","bar ","baz.\n");
#if 0
char* c="fnord";
int fd=open_read(c);
errmsg_iam(argv[0]);
carp("could not open file `",c,"'");
diesys(23,"could not open file `",c,"'");
#endif
#if 0
errmsg_warn("could not open file `",c,"'",0);
errmsg_warnsys("could not open file `",c,"'",0);


불러오는 중...
취소
저장