Browse Source

implement Nikola's idea to remove limit number of strings in errmsg

master
Felix von Leitner 15 years ago
parent
commit
c89e6b4fcc
10 changed files with 71 additions and 142 deletions
  1. +1
    -0
      CHANGES
  2. +0
    -39
      buffer/errmsg_cvt.c
  3. +2
    -25
      buffer/errmsg_info.c
  4. +2
    -4
      buffer/errmsg_infosys.c
  5. +41
    -0
      buffer/errmsg_puts.c
  6. +2
    -25
      buffer/errmsg_warn.c
  7. +2
    -4
      buffer/errmsg_warnsys.c
  8. +20
    -0
      buffer/errmsg_write.c
  9. +0
    -44
      buffer/errmsg_writesys.c
  10. +1
    -1
      t.c

+ 1
- 0
CHANGES View File

@@ -7,6 +7,7 @@
further Windoze support (test/io5.c works, gatling still doesn't)
This is just to get gatling to work, I may remove it again after
that.
implement Nikola's idea to remove limit number of strings in errmsg

0.24:
fix scan_to_sa (Tim Lorenz)


+ 0
- 39
buffer/errmsg_cvt.c View File

@@ -1,39 +0,0 @@
#include <stdarg.h>
#include <sys/types.h>
#ifdef __MINGW32__
#include "windows.h"

struct iovec {
LPCVOID iov_base;
DWORD iov_len;
};
#else
#include <sys/uio.h>
#endif
#include "errmsg.h"
#include "str.h"

/* the people who defined stdarg.h need to be taken behind the barn and shot */
int errmsg_cvt(struct iovec* x,const char* message, va_list a) {
int i,j;
j=0;
if (argv0) {
x[0].iov_base=(char*)argv0;
x[0].iov_len=str_len(argv0);
x[1].iov_base=": ";
x[1].iov_len=2;
j=2;
}
x[j].iov_base=(char*)message; x[j].iov_len=str_len(message); ++j;

for (i=0; j<22; ++i) {
const char* t=va_arg(a,const char*);
if (!t) break;
x[j].iov_base=(char*)t;
x[j].iov_len=str_len(t);
++j;
}
x[j].iov_base="\n";
x[j].iov_len=1;
return j+1;
}

+ 2
- 25
buffer/errmsg_info.c View File

@@ -1,34 +1,11 @@
#include <stdarg.h>
#include <sys/types.h>
#ifdef __MINGW32__
#include "windows.h"
#include <unistd.h>

struct iovec {
LPCVOID iov_base;
DWORD iov_len;
};
#else
#include <sys/uio.h>
#endif
#include "errmsg.h"
#include "errmsg_int.h"
#include "str.h"

extern int errmsg_cvt(struct iovec* x,const char* message, va_list a);

void errmsg_info(const char* message, ...) {
struct iovec x[23];
va_list a;
va_start(a,message);
#ifdef __MINGW32__
{
int i,j;
j=errmsg_cvt(x,message,a);
for (i=0; i<j; ++i)
write(1,x[i].iov_base,x[i].iov_len);
}
#else
writev(1,x,errmsg_cvt(x,message,a));
#endif
va_end(a);
errmsg_write(1,0,message,a);
}

+ 2
- 4
buffer/errmsg_infosys.c View File

@@ -1,15 +1,13 @@
#include <stdarg.h>
#include <sys/types.h>
#include "errmsg.h"
#include "errmsg_int.h"
#include "str.h"
#include <string.h>
#include <errno.h>

extern void errmsg_writesys(int fd,const char* message,va_list list);

void errmsg_infosys(const char* message, ...) {
va_list a;
va_start(a,message);
errmsg_writesys(1,message,a);
va_end(a);
errmsg_write(1,strerror(errno),message,a);
}

+ 41
- 0
buffer/errmsg_puts.c View File

@@ -0,0 +1,41 @@
#include "errmsg.h"
#include "errmsg_int.h"
#include <str.h>

#ifdef __MINGW32__

void errmsg_puts(int fd,const char* s) {
return write(fd,s,str_len(s));
}

void errmsg_flush(int fd) {
return 0;
}

#else
#include <sys/uio.h>

enum { COUNT=25 };
static struct iovec x[COUNT];
static int l;

void errmsg_puts(int fd,const char* s) {
x[l].iov_base=(char*)s;
x[l].iov_len=str_len(s);
if (++l==COUNT) errmsg_flush(fd);
}

void errmsg_flush(int fd) {
int n=l;
l=0;
if (n) writev(fd,x,n);
}
#endif

void errmsg_start(int fd) {
if (argv0) {
errmsg_puts(fd,argv0);
errmsg_puts(fd,": ");
}
}


+ 2
- 25
buffer/errmsg_warn.c View File

@@ -1,34 +1,11 @@
#include <stdarg.h>
#include <sys/types.h>
#ifdef __MINGW32__
#include "windows.h"
#include <unistd.h>

struct iovec {
LPCVOID iov_base;
DWORD iov_len;
};
#else
#include <sys/uio.h>
#endif
#include "errmsg.h"
#include "errmsg_int.h"
#include "str.h"

extern int errmsg_cvt(struct iovec* x,const char* message, va_list a);

void errmsg_warn(const char* message, ...) {
struct iovec x[23];
va_list a;
va_start(a,message);
#ifdef __MINGW32__
{
int i,j;
j=errmsg_cvt(x,message,a);
for (i=0; i<j; ++i)
write(2,x[i].iov_base,x[i].iov_len);
}
#else
writev(2,x,errmsg_cvt(x,message,a));
#endif
va_end(a);
errmsg_write(2,0,message,a);
}

+ 2
- 4
buffer/errmsg_warnsys.c View File

@@ -1,15 +1,13 @@
#include <stdarg.h>
#include <sys/types.h>
#include "errmsg.h"
#include "errmsg_int.h"
#include "str.h"
#include <string.h>
#include <errno.h>

extern void errmsg_writesys(int fd,const char* message,va_list list);

void errmsg_warnsys(const char* message, ...) {
va_list a;
va_start(a,message);
errmsg_writesys(2,message,a);
va_end(a);
errmsg_write(2,strerror(errno),message,a);
}

+ 20
- 0
buffer/errmsg_write.c View File

@@ -0,0 +1,20 @@
#include <stdarg.h>
#include "errmsg.h"
#include "errmsg_int.h"

void errmsg_write(int fd,const char* err,const char* message,va_list list) {
errmsg_start(fd);
errmsg_puts(fd,message);
for (;;) {
const char* s=va_arg(list,const char*);
if (!s) break;
errmsg_puts(fd,s);
}
va_end(list);
if (err) {
errmsg_puts(fd,": ");
errmsg_puts(fd,err);
}
errmsg_puts(fd,"\n");
errmsg_flush(fd);
}

+ 0
- 44
buffer/errmsg_writesys.c View File

@@ -1,44 +0,0 @@
#include <stdarg.h>
#include <sys/types.h>
#ifdef __MINGW32__
#include "windows.h"
#include <unistd.h>

struct iovec {
LPCVOID iov_base;
DWORD iov_len;
};
#else
#include <sys/uio.h>
#endif
#include "errmsg.h"
#include "str.h"
#include <string.h>
#include <errno.h>

extern int errmsg_cvt(struct iovec* x,const char* message, va_list a);

void errmsg_writesys(int fd,const char* message,va_list list) {
struct iovec x[25];
int i;
i=errmsg_cvt(x,message,list);

x[i-1].iov_base=": ";
x[i-1].iov_len=2;

x[i].iov_base=strerror(errno);
x[i].iov_len=str_len(x[i].iov_base);

x[i+1].iov_base="\n";
x[i+1].iov_len=1;

#ifdef __MINGW32__
{
int j;
for (j=0; j<i+2; ++j)
write(fd,x[j].iov_base,x[j].iov_len);
}
#else
writev(fd,x,i+2);
#endif
}

+ 1
- 1
t.c View File

@@ -64,7 +64,7 @@ int main(int argc,char* argv[]) {
#if 0
buffer_putmflush(buffer_1,"foo ","bar ","baz.\n");
#endif
#if 0
#if 1
char* c="fnord";
int fd=open_read(c);
errmsg_iam(argv[0]);


Loading…
Cancel
Save