more constness for stralloc and buffer

master
leitner 10 years ago
parent 38ea25fd9f
commit ed93e203a1

@ -23,6 +23,7 @@
TCP_CORK (saves two syscalls) TCP_CORK (saves two syscalls)
add io_fd_flags so the caller can tell io_fd whether the socket is blocking add io_fd_flags so the caller can tell io_fd whether the socket is blocking
(saves one fcntl syscall) (saves one fcntl syscall)
more constness for stralloc and buffer
0.29: 0.29:
save 8 bytes in taia.h for 64-bit systems save 8 bytes in taia.h for 64-bit systems

@ -107,9 +107,9 @@ extern buffer *buffer_2;
#ifdef STRALLOC_H #ifdef STRALLOC_H
/* write stralloc to buffer */ /* write stralloc to buffer */
int buffer_putsa(buffer* b,stralloc* sa); int buffer_putsa(buffer* b,const stralloc* sa);
/* write stralloc to buffer and flush */ /* write stralloc to buffer and flush */
int buffer_putsaflush(buffer* b,stralloc* sa); int buffer_putsaflush(buffer* b,const stralloc* sa);
/* these "read token" functions return 0 if the token was complete or /* these "read token" functions return 0 if the token was complete or
* EOF was hit or -1 on error. In contrast to the non-stralloc token * EOF was hit or -1 on error. In contrast to the non-stralloc token
@ -141,7 +141,7 @@ int buffer_get_new_token_sa_pred(buffer* b,stralloc* sa,sa_predicate p);
/* make a buffer from a stralloc. /* make a buffer from a stralloc.
* Do not change the stralloc after this! */ * Do not change the stralloc after this! */
void buffer_fromsa(buffer* b,stralloc* sa); /* read from sa */ void buffer_fromsa(buffer* b,const stralloc* sa); /* read from sa */
int buffer_tosa(buffer*b,stralloc* sa); /* write to sa, auto-growing it */ int buffer_tosa(buffer*b,stralloc* sa); /* write to sa, auto-growing it */
#endif #endif

@ -4,7 +4,7 @@ buffer_fromsa \- initialize buffer structure from stralloc
.SH SYNTAX .SH SYNTAX
.B #include <buffer.h> .B #include <buffer.h>
void \fBbuffer_fromsa\fR(buffer* \fIb\fR,stralloc* \fIsa\fR); void \fBbuffer_fromsa\fR(buffer* \fIb\fR,const stralloc* \fIsa\fR);
.SH DESCRIPTION .SH DESCRIPTION
buffer_fromsa makes a virtual read buffer from a stralloc. The buffer buffer_fromsa makes a virtual read buffer from a stralloc. The buffer
reading functions will be able to read until the end of the data in the reading functions will be able to read until the end of the data in the

@ -1,6 +1,6 @@
#include "stralloc.h" #include "stralloc.h"
#include "buffer.h" #include "buffer.h"
void buffer_fromsa(buffer* b,stralloc* sa) { void buffer_fromsa(buffer* b,const stralloc* sa) {
buffer_frombuf(b,sa->s,sa->len); buffer_frombuf(b,sa->s,sa->len);
} }

@ -6,9 +6,9 @@ buffer_putsa \- write stralloc to buffer
.B #include <stralloc.h> .B #include <stralloc.h>
.B #include <buffer.h> .B #include <buffer.h>
int \fBbuffer_putsa\fP(buffer* \fIb\fR,stralloc* \fIx\fR); int \fBbuffer_putsa\fP(buffer* \fIb\fR,const stralloc* \fIx\fR);
.SH DESCRIPTION .SH DESCRIPTION
buffer_putsa is equivalent to buffer_put(b,x.sa,x.len). buffer_putsa is equivalent to buffer_put(b,x.s,x.len).
.SH "RETURN VALUE" .SH "RETURN VALUE"
0 if everything is fine, -1 on error (setting \fIerrno\fR). 0 if everything is fine, -1 on error (setting \fIerrno\fR).
.SH "SEE ALSO" .SH "SEE ALSO"

@ -1,6 +1,6 @@
#include "stralloc.h" #include "stralloc.h"
#include "buffer.h" #include "buffer.h"
int buffer_putsa(buffer* b,stralloc* sa) { int buffer_putsa(buffer* b,const stralloc* sa) {
return buffer_put(b,sa->s,sa->len); return buffer_put(b,sa->s,sa->len);
} }

@ -6,9 +6,9 @@ buffer_putsa \- write stralloc to buffer and flush
.B #include <stralloc.h> .B #include <stralloc.h>
.B #include <buffer.h> .B #include <buffer.h>
int \fBbuffer_putsaflush\fP(buffer* \fIb\fR,const char* \fIx\fR); int \fBbuffer_putsaflush\fP(buffer* \fIb\fR,const stralloc* \fIx\fR);
.SH DESCRIPTION .SH DESCRIPTION
buffer_putsaflush is equivalent to buffer_putflush(b,x.sa,x.len). buffer_putsaflush is equivalent to buffer_putflush(b,x.s,x.len).
.SH "RETURN VALUE" .SH "RETURN VALUE"
0 if everything is fine, -1 on error (setting \fIerrno\fR). 0 if everything is fine, -1 on error (setting \fIerrno\fR).
.SH "SEE ALSO" .SH "SEE ALSO"

@ -1,6 +1,6 @@
#include "stralloc.h" #include "stralloc.h"
#include "buffer.h" #include "buffer.h"
int buffer_putsaflush(buffer* b,stralloc* sa) { int buffer_putsaflush(buffer* b,const stralloc* sa) {
return buffer_putflush(b,sa->s,sa->len); return buffer_putflush(b,sa->s,sa->len);
} }

@ -76,7 +76,7 @@ int stralloc_catm_internal(stralloc* sa,...);
#define stralloc_copym(sa,...) (stralloc_zero(sa), stralloc_catm_internal(sa,__VA_ARGS__,(char*)0)) #define stralloc_copym(sa,...) (stralloc_zero(sa), stralloc_catm_internal(sa,__VA_ARGS__,(char*)0))
/* stralloc_cat is analogous to stralloc_copy */ /* stralloc_cat is analogous to stralloc_copy */
int stralloc_cat(stralloc* sa,stralloc* in); int stralloc_cat(stralloc* sa,const stralloc* in);
/* stralloc_append adds one byte in[0] to the end of the string stored /* stralloc_append adds one byte in[0] to the end of the string stored
* in sa. It is the same as stralloc_catb(&sa,in,1). */ * in sa. It is the same as stralloc_catb(&sa,in,1). */
@ -129,9 +129,9 @@ int stralloc_chomp(stralloc* sa);
#ifdef BUFFER_H #ifdef BUFFER_H
/* write stralloc to buffer */ /* write stralloc to buffer */
int buffer_putsa(buffer* b,stralloc* sa); int buffer_putsa(buffer* b,const stralloc* sa);
/* write stralloc to buffer and flush */ /* write stralloc to buffer and flush */
int buffer_putsaflush(buffer* b,stralloc* sa); int buffer_putsaflush(buffer* b,const stralloc* sa);
/* these "read token" functions return 1 for a complete token, 0 if /* these "read token" functions return 1 for a complete token, 0 if
* EOF was hit or -1 on error. In contrast to the non-stralloc token * EOF was hit or -1 on error. In contrast to the non-stralloc token
@ -164,7 +164,7 @@ int buffer_get_new_token_sa_pred(buffer* b,stralloc* sa,sa_predicate p);
/* make a buffer (for reading) from a stralloc. /* make a buffer (for reading) from a stralloc.
* Do not change the stralloc after this! */ * Do not change the stralloc after this! */
void buffer_fromsa(buffer* b,stralloc* sa); void buffer_fromsa(buffer* b,const stralloc* sa);
int buffer_tosa(buffer*b,stralloc* sa); /* write to sa, auto-growing it */ int buffer_tosa(buffer*b,stralloc* sa); /* write to sa, auto-growing it */
#endif #endif

@ -4,7 +4,7 @@ stralloc_cat \- append data to a stralloc
.SH SYNTAX .SH SYNTAX
.B #include <stralloc.h> .B #include <stralloc.h>
int \fBstralloc_cat\fP(stralloc* \fIsato\fR,stralloc* \fIsafrom\fR); int \fBstralloc_cat\fP(stralloc* \fIsato\fR,const stralloc* \fIsafrom\fR);
.SH DESCRIPTION .SH DESCRIPTION
stralloc_cat appends the string stored in \fIsafrom\fR to \fIsa\fR. It stralloc_cat appends the string stored in \fIsafrom\fR to \fIsa\fR. It
is the same as is the same as

@ -1,7 +1,7 @@
#include "stralloc.h" #include "stralloc.h"
#include "str.h" #include "str.h"
extern int stralloc_cat(stralloc *sa,stralloc *sa2) { extern int stralloc_cat(stralloc *sa,const stralloc *sa2) {
return stralloc_catb(sa,sa2->s,sa2->len); return stralloc_catb(sa,sa2->s,sa2->len);
} }

Loading…
Cancel
Save