1
1
/* POSIX compatible FILE stream write function.
2
Copyright (C) 2008-2009 Free Software Foundation, Inc.
2
Copyright (C) 2008-2011 Free Software Foundation, Inc.
3
3
Written by Bruno Haible <bruno@clisp.org>, 2008.
5
5
This program is free software: you can redistribute it and/or modify
20
20
/* Specification. */
23
/* Replace these functions only if module 'sigpipe' is requested. */
23
/* Replace these functions only if module 'nonblocking' or module 'sigpipe' is
25
#if GNULIB_NONBLOCKING || GNULIB_SIGPIPE
26
27
/* On native Windows platforms, SIGPIPE does not exist. When write() is
27
28
called on a pipe with no readers, WriteFile() fails with error
38
39
# define WIN32_LEAN_AND_MEAN /* avoid including junk */
39
40
# include <windows.h>
42
# if GNULIB_NONBLOCKING
43
# define CLEAR_ERRNO \
45
# define HANDLE_ENOSPC \
46
if (errno == ENOSPC && ferror (stream)) \
48
int fd = fileno (stream); \
51
HANDLE h = (HANDLE) _get_osfhandle (fd); \
52
if (GetFileType (h) == FILE_TYPE_PIPE) \
54
/* h is a pipe or socket. */ \
56
if (GetNamedPipeHandleState (h, &state, NULL, NULL, \
58
&& (state & PIPE_NOWAIT) != 0) \
59
/* h is a pipe in non-blocking mode. \
60
Change errno from ENOSPC to EAGAIN. */ \
68
# define HANDLE_ENOSPC
72
# define CLEAR_LastError \
74
# define HANDLE_ERROR_NO_DATA \
75
if (GetLastError () == ERROR_NO_DATA && ferror (stream)) \
77
int fd = fileno (stream); \
79
&& GetFileType ((HANDLE) _get_osfhandle (fd)) \
82
/* Try to raise signal SIGPIPE. */ \
84
/* If it is currently blocked or ignored, change errno from \
91
# define CLEAR_LastError
92
# define HANDLE_ERROR_NO_DATA
41
95
# define CALL_WITH_SIGPIPE_EMULATION(RETTYPE, EXPRESSION, FAILED) \
42
if (ferror (stream)) \
43
return (EXPRESSION); \
49
if (FAILED && GetLastError () == ERROR_NO_DATA && ferror (stream)) \
51
int fd = fileno (stream); \
53
&& GetFileType ((HANDLE) _get_osfhandle (fd)) == FILE_TYPE_PIPE)\
55
/* Try to raise signal SIGPIPE. */ \
57
/* If it is currently blocked or ignored, change errno from \
96
if (ferror (stream)) \
97
return (EXPRESSION); \
103
ret = (EXPRESSION); \
107
HANDLE_ERROR_NO_DATA \
65
113
# if !REPLACE_PRINTF_POSIX /* avoid collision with printf.c */
66
# if !DEPENDS_ON_LIBINTL /* avoid collision with intl/printf.c */
68
115
printf (const char *format, ...)