File: errmsg_puts.c

package info (click to toggle)
libowfat 0.34-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,288 kB
  • sloc: ansic: 20,181; makefile: 16
file content (41 lines) | stat: -rw-r--r-- 611 bytes parent folder | download | duplicates (3)
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
40
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,": ");
  }
}