Bump to release 1.4.0
[smenu.git] / safe.c
blob5b2213d430eefb226b1bf84337a1e204c8219159
1 /* ################################################################### */
2 /* Copyright 2015, Pierre Gentile (p.gen.progs@gmail.com) */
3 /* */
4 /* This Source Code Form is subject to the terms of the Mozilla Public */
5 /* License, v. 2.0. If a copy of the MPL was not distributed with this */
6 /* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
7 /* ################################################################### */
9 /* ************************************ */
10 /* Some wrappers to manage EINTR errors */
11 /* ************************************ */
13 #include <stdio.h>
14 #include <termios.h>
15 #include <unistd.h>
16 #include <sys/stat.h>
17 #include <fcntl.h>
18 #include <errno.h>
20 #include "safe.h"
22 FILE *
23 fopen_safe(const char * restrict stream, const char * restrict mode)
25 FILE *file;
27 while ((file = fopen(stream, mode)) == NULL && errno == EINTR)
30 return file;
33 int
34 tcsetattr_safe(int fildes,
35 int optional_actions,
36 const struct termios *termios_p)
38 int res;
40 while ((res = tcsetattr(fildes, optional_actions, termios_p)) == -1
41 && errno == EINTR)
44 return res;
47 int
48 fputc_safe(int c, FILE *stream)
50 int res;
52 while ((res = fputc(c, stream)) == -1 && errno == EINTR)
55 return res;
58 int
59 fputs_safe(const char * restrict s, FILE * restrict stream)
61 int res;
63 while ((res = fputs(s, stream)) == -1 && errno == EINTR)
66 return res;