File: errmsg_cvt.c

package info (click to toggle)
libowfat 0.22-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,148 kB
  • ctags: 976
  • sloc: ansic: 10,424; makefile: 42
file content (39 lines) | stat: -rw-r--r-- 791 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#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;
}