cfengine  3.15.4
About: CFEngine is a configuration management system for configuring and maintaining Unix-like computers (using an own high level policy language). Community version.
  Fossies Dox: cfengine-3.15.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

platform.h
Go to the documentation of this file.
1 /*
2  Copyright 2020 Northern.tech AS
3 
4  This file is part of CFEngine 3 - written and maintained by Northern.tech AS.
5 
6  This program is free software; you can redistribute it and/or modify it
7  under the terms of the GNU General Public License as published by the
8  Free Software Foundation; version 3.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
18 
19  To the extent this program is licensed as part of the Enterprise
20  versions of CFEngine, the applicable Commercial Open Source License
21  (COSL) may apply to this file if you as a licensee so wish it. See
22  included file COSL.txt.
23 */
24 
25 #ifndef CFENGINE_PLATFORM_H
26 #define CFENGINE_PLATFORM_H
27 
28 /*
29  * Platform-specific definitions and declarations.
30  *
31  * INCLUDE THIS HEADER ALWAYS FIRST in order to define appropriate macros for
32  * including system headers (such as _FILE_OFFSET_BITS).
33  */
34 
35 #ifdef HAVE_CONFIG_H
36 # include <config.h>
37 #endif
38 
39 #define _GNU_SOURCE 1
40 
41 #ifdef _WIN32
42 # define MAX_FILENAME 227
43 # define WINVER 0x501
44 # if defined(__CYGWIN__)
45 # undef FD_SETSIZE
46 # endif
47  /* Increase select(2) FD limit from 64. It's documented and valid to do it
48  * like that provided that we define it *before* including winsock2.h. */
49 # define FD_SETSIZE 4096
50 #else
51 # define MAX_FILENAME 254
52 #endif
53 
54 #ifdef __MINGW32__
55 # include <winsock2.h>
56 # include <windows.h>
57 # include <accctrl.h>
58 # include <aclapi.h>
59 # include <psapi.h>
60 # include <wchar.h>
61 # include <sddl.h>
62 # include <tlhelp32.h>
63 # include <iphlpapi.h>
64 # include <ws2tcpip.h>
65 # include <objbase.h> // for disphelper
66 # ifndef SHUT_RDWR // for shutdown()
67 # define SHUT_RDWR SD_BOTH
68 # endif
69 #endif
70 
71 /* Standard C. */
72 #include <stdio.h>
73 #include <math.h>
74 #include <string.h>
75 #include <ctype.h>
76 #include <assert.h>
77 #include <stddef.h> /* offsetof, size_t */
78 
79 /* POSIX but available in all platforms. */
80 #include <strings.h>
81 #include <limits.h>
82 
83 #ifdef HAVE_SYS_SYSMACROS_H
84 # include <sys/sysmacros.h>
85 #endif
86 
87 #include <sys/types.h>
88 #include <sys/stat.h>
89 
90 /* We now require a pthreads implementation. */
91 #include <pthread.h>
92 
93 #ifndef _GETOPT_H
94 # include <../libcompat/getopt.h>
95 #endif
96 
97 #ifdef HAVE_STDLIB_H
98 # include <stdlib.h>
99 #endif
100 
101 #ifdef HAVE_UNAME
102 # include <sys/utsname.h>
103 #else
104 # define _SYS_NMLN 257
105 
106 struct utsname
107 {
113 };
114 
115 #endif
116 
117 #ifdef HAVE_STDINT_H
118 # include <stdint.h>
119 #endif
120 
121 #ifdef HAVE_INTTYPES_H
122 # include <inttypes.h>
123 #endif
124 
125 #ifdef HAVE_SYS_SYSTEMINFO_H
126 # include <sys/systeminfo.h>
127 #endif
128 
129 #ifdef HAVE_SYS_PARAM_H
130 # include <sys/param.h>
131 #endif
132 
133 #ifdef HAVE_SYS_MOUNT_H
134 # include <sys/mount.h>
135 #endif
136 
137 #ifdef HAVE_SYS_WAIT_H
138 # include <sys/wait.h>
139 #endif
140 #ifndef WEXITSTATUS
141 # define WEXITSTATUS(s) ((unsigned)(s) >> 8)
142 #endif
143 #ifndef WIFEXITED
144 # define WIFEXITED(s) (((s) & 255) == 0)
145 #endif
146 #ifndef WIFSIGNALED
147 # define WIFSIGNALED(s) ((s) & 0) /* Can't use for BSD */
148 #endif
149 #ifndef WTERMSIG
150 # define WTERMSIG(s) ((s) & 0)
151 #endif
152 
153 #include <stdbool.h>
154 
155 #include <errno.h>
156 
157 #ifdef HAVE_DIRENT_H
158 # include <dirent.h>
159 #else
160 # define dirent direct
161 # if HAVE_SYS_NDIR_H
162 # include <sys/ndir.h>
163 # endif
164 # if HAVE_SYS_DIR_H
165 # include <sys/dir.h>
166 # endif
167 # if HAVE_NDIR_H
168 # include <ndir.h>
169 # endif
170 #endif
171 
172 #ifndef PATH_MAX
173 # ifdef _MAX_PATH
174 # define PATH_MAX _MAX_PATH
175 # else
176 # define PATH_MAX 4096
177 # endif
178 #endif
179 
180 #include <signal.h>
181 
182 #ifdef __MINGW32__
183 # define LOG_LOCAL0 (16<<3)
184 # define LOG_LOCAL1 (17<<3)
185 # define LOG_LOCAL2 (18<<3)
186 # define LOG_LOCAL3 (19<<3)
187 # define LOG_LOCAL4 (20<<3)
188 # define LOG_LOCAL5 (21<<3)
189 # define LOG_LOCAL6 (22<<3)
190 # define LOG_LOCAL7 (23<<3)
191 # define LOG_USER (1<<3)
192 # define LOG_DAEMON (3<<3)
193 
194 /* MinGW added this flag only in latest version. */
195 # ifndef IPV6_V6ONLY
196 # define IPV6_V6ONLY 27
197 # endif
198 
199 // Not available in MinGW headers unless you raise WINVER and _WIN32_WINNT, but
200 // that is very badly supported in MinGW ATM.
201 ULONGLONG WINAPI GetTickCount64(void);
202 
203 #else /* !__MINGW32__ */
204 # include <syslog.h>
205 #endif
206 
207 #ifdef _AIX
208 # ifndef ps2
209 # include <sys/statfs.h>
210 # endif
211 
212 # include <sys/systemcfg.h>
213 #endif
214 
215 #ifdef __sun
216 # include <sys/statvfs.h>
217 # undef nfstype
218 
219 #include <sys/mkdev.h>
220 
221 #ifndef timersub
222 # define timersub(a, b, result) \
223  do \
224  { \
225  (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
226  (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
227  if ((result)->tv_usec < 0) \
228  { \
229  --(result)->tv_sec; \
230  (result)->tv_usec += 1000000; \
231  } \
232  } while (0)
233 #endif
234 
235 #endif
236 
237 #if !HAVE_DECL_DIRFD
238 int dirfd(DIR *dirp);
239 #endif
240 
241 /* strndup is defined as a macro on many systems */
242 #if !HAVE_DECL_STRNDUP
243 # ifndef strndup
244 char *strndup(const char *s, size_t n);
245 # endif
246 #endif
247 
248 #if !HAVE_DECL_STRNLEN
249 size_t strnlen(const char *str, size_t maxlen);
250 #endif
251 
252 #ifdef HAVE_UNISTD_H
253 # include <unistd.h>
254 #endif
255 
256 #if !HAVE_DECL_STRLCPY
257 size_t strlcpy(char *destination, const char *source, size_t size);
258 #endif
259 
260 #if !HAVE_DECL_STRLCAT
261 size_t strlcat(char *destination, const char *source, size_t size);
262 #endif
263 
264 #if !HAVE_DECL_STRSEP
265 char *strsep(char **stringp, const char *delim);
266 #endif
267 
268 #if !HAVE_DECL_SOCKETPAIR
269 int socketpair(int domain, int type, int protocol, int sv[2]);
270 #endif
271 
272 #if !HAVE_DECL_FSYNC
273 int fsync(int fd);
274 #endif
275 
276 #if !HAVE_DECL_GLOB
277 #define GLOB_NOSPACE 1
278 #define GLOB_ABORTED 2
279 #define GLOB_NOMATCH 3
280 typedef struct {
281  size_t gl_pathc; /* Count of paths matched so far */
282  char **gl_pathv; /* List of matched pathnames. */
283  size_t gl_offs;
284 } glob_t;
285 int glob(const char *pattern,
286  int flags,
287  int (*errfunc) (const char *epath, int eerrno),
288  glob_t *pglob);
289 void globfree(glob_t *pglob);
290 #endif
291 
292 #ifdef __APPLE__
293 # include <sys/malloc.h>
294 # include <sys/paths.h>
295 #endif
296 
297 #ifdef HAVE_SYS_MALLOC_H
298 # ifdef __APPLE__
299 # include <sys/malloc.h>
300 # include <sys/paths.h>
301 # endif
302 #else
303 # ifdef HAVE_MALLOC_H
304 # ifndef __OpenBSD__
305 # ifdef __FreeBSD__
306 # include <stdlib.h>
307 # else
308 # include <malloc.h>
309 # endif
310 # endif
311 # endif
312 #endif
313 
314 #include <fcntl.h>
315 
316 #ifdef HAVE_VFS_H
317 # include <sys/vfs.h>
318 #endif
319 
320 #ifdef __hpux
321 # include <sys/dirent.h>
322 #endif
323 
324 #ifdef HAVE_UTIME_H
325 # include <utime.h> /* use utime not utimes for portability */
326 #elif TIME_WITH_SYS_TIME
327 # include <sys/time.h>
328 # include <time.h>
329 #elif HAVE_SYS_TIME_H
330 # include <sys/time.h>
331 #elif ! defined(AOS)
332 # include <time.h>
333 #endif
334 
335 #ifdef HAVE_TIME_H
336 # include <time.h>
337 #endif
338 
339 #ifdef HAVE_SYS_TIME_H
340 # include <sys/time.h>
341 #endif
342 
343 #ifdef HAVE_SYS_RESOURCE_H
344 # include <sys/resource.h>
345 #endif
346 
347 #ifndef __MINGW32__
348 # include <pwd.h>
349 # include <grp.h>
350 #endif
351 
352 #ifdef HAVE_SYS_SOCKIO_H
353 # include <sys/sockio.h>
354 #endif
355 
356 /*
357  Work around bug in HPUX system headers:
358  "/usr/include/machine/sys/getppdp.h:65: error: array type has incomplete element type"
359 */
360 #ifdef __hpux
361 union mpinfou
362 {
363  int dummy;
364 };
365 #endif
366 
367 #ifndef __MINGW32__
368 # include <sys/socket.h>
369 # include <sys/ioctl.h>
370 # include <net/if.h>
371 # include <netinet/in.h>
372 # include <netinet/in_systm.h>
373 # include <netinet/ip.h>
374 # include <netinet/tcp.h>
375 # include <arpa/inet.h>
376 # include <netdb.h>
377 # if !defined __linux__ && !defined _WIN32
378 # include <sys/protosw.h>
379 # undef sgi
380 # include <net/route.h>
381 # endif
382 #endif
383 
384 #ifdef __linux__
385 # ifdef HAVE_NET_ROUTE_H
386 # include <net/route.h>
387 # else
388 # include <linux/route.h>
389 # endif
390 
391 # ifdef HAVE_NETINET_IN_H
392 # include <netinet/in.h>
393 # else
394 # include <linux/in.h>
395 # endif
396 
397 # ifdef HAVE_NETINET_IP_H
398 # include <netinet/ip.h>
399 # else
400 # include <linux/ip.h>
401 # endif
402 #endif
403 
404 #ifdef __linux__
405 #define ARG_LINUX_ONLY
406 #else
407 #define ARG_LINUX_ONLY ARG_UNUSED
408 #endif
409 
410 #ifndef CLOCK_REALTIME
411 # define CLOCK_REALTIME 1
412 #endif
413 
414 #ifndef HAVE_CLOCKID_T
415 typedef int clockid_t;
416 #endif
417 
418 #ifndef HAVE_SOCKLEN_T
419 typedef int socklen_t;
420 #endif
421 
422 # ifndef _SC_THREAD_STACK_MIN
423 # define _SC_THREAD_STACK_MIN PTHREAD_STACK_MIN
424 #endif
425 
426 #ifndef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
427 # define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP PTHREAD_MUTEX_INITIALIZER
428 #endif
429 
430 #if !HAVE_DECL_GETLOADAVG
431 int getloadavg (double loadavg[], int nelem);
432 #endif
433 
434 #ifdef HAVE_ENDIAN_H
435 # include <endian.h>
436 #endif
437 
438 #if !HAVE_DECL_LE32TOH
439 static inline uint32_t ByteSwap32(uint32_t le32uint)
440 {
441  uint32_t be32uint;
442  unsigned char *le_ptr = (unsigned char *)&le32uint;
443  unsigned char *be_ptr = (unsigned char *)&be32uint;
444  be_ptr[0] = le_ptr[3];
445  be_ptr[1] = le_ptr[2];
446  be_ptr[2] = le_ptr[1];
447  be_ptr[3] = le_ptr[0];
448  return be32uint;
449 }
450 # ifdef WORDS_BIGENDIAN
451 # define le32toh(x) ByteSwap32(x)
452 # define htole32(x) ByteSwap32(x)
453 # else
454 # define le32toh(x) (x)
455 # define htole32(x) (x)
456 # endif
457 #endif // !HAVE_DECL_LE32TOH
458 
459 #if !HAVE_DECL_CLOSEFROM
460 int closefrom(int fd);
461 #endif
462 
463 #if !HAVE_DECL_PTHREAD_ATTR_SETSTACKSIZE
464 int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);
465 #endif
466 
467 #ifdef HAVE_SCHED_H
468 # include <sched.h>
469 #endif
470 
471 #if defined(HAVE_SYS_XATTR_H)
472 # include <sys/xattr.h>
473 #elif defined(HAVE_ATTR_XATTR_H)
474 # include <attr/xattr.h>
475 #endif
476 
477 #ifndef MIN
478 # define MIN(a, b) ((a) < (b) ? (a) : (b))
479 #endif
480 
481 #ifndef MAX
482 # define MAX(a, b) ((a) > (b) ? (a) : (b))
483 #endif
484 
485 #ifndef INADDR_NONE
486 # define INADDR_NONE ((unsigned long int) 0xffffffff)
487 #endif
488 #ifndef HAVE_SETEGID
489 int setegid(gid_t gid);
490 #endif
491 #if !HAVE_DECL_UNAME
492 int uname(struct utsname *buf);
493 #endif
494 #if !HAVE_DECL_GETUID
495 uid_t getuid(void);
496 #endif
497 #if !HAVE_DECL_GETGID
498 gid_t getgid(void);
499 #endif
500 #if !HAVE_DECL_FGETGRENT
501 struct group *fgetgrent(FILE *stream);
502 #endif
503 #if !HAVE_DECL_DRAND48
504 double drand48(void);
505 #endif
506 #if !HAVE_DECL_SRAND48
507 void srand48(long seed);
508 #endif
509 #if !HAVE_DECL_CLOCK_GETTIME
510 int clock_gettime(clockid_t clock_id, struct timespec *tp);
511 #endif
512 
513 #if !HAVE_DECL_REALPATH
514  /**
515  * WARNING realpath() has varying behaviour among platforms.
516  * - Do not use it to convert relative paths to absolute
517  * (Solaris under certain conditions will return relative path).
518  * - Do not use it to check existence of file
519  * (on *BSD the last component of the path may not exist).
520  * Use it only to resolve all symlinks and canonicalise filename,
521  * i.e. remove double '/' and "/./" and "/../".
522  *
523  * @TODO what we need is a resolvepath(2) cross-platform implementation.
524  */
525 # if defined (__MINGW32__)
526 # define realpath(N,R) _fullpath((R), (N), PATH_MAX)
527 # endif
528 #endif
529 
530 #if !HAVE_DECL_LSTAT
531 int lstat(const char *file_name, struct stat *buf);
532 #endif
533 #if !HAVE_DECL_SLEEP
534 unsigned int sleep(unsigned int seconds);
535 #endif
536 #if !HAVE_DECL_ROUND
537 double round(double x);
538 #endif
539 #if !HAVE_DECL_NANOSLEEP
540 int nanosleep(const struct timespec *req, struct timespec *rem);
541 #endif
542 #if !HAVE_DECL_CHOWN
543 int chown(const char *path, uid_t owner, gid_t group);
544 #endif
545 #if !HAVE_DECL_FCHMOD
546 int fchmod(int fd, mode_t mode);
547 #endif
548 
549 #if !HAVE_DECL_GETNETGRENT
550 int getnetgrent(char **host, char **user, char **domain);
551 #endif
552 
553 #if !HAVE_DECL_SETNETGRENT
554 #if SETNETGRENT_RETURNS_INT
555 int
556 #else
557 void
558 #endif
559 setnetgrent(const char *netgroup);
560 #endif
561 
562 #if !HAVE_DECL_ENDNETGRENT
563 #if ENDNETGRENT_RETURNS_INT
564 int
565 #else
566 void
567 #endif
568 endnetgrent(void);
569 #endif
570 
571 #if !HAVE_DECL_STRSTR
572 char *strstr(const char *haystack, const char *needle);
573 #endif
574 #if !HAVE_DECL_STRCASESTR
575 char *strcasestr(const char *haystack, const char *needle);
576 #endif
577 #if !HAVE_DECL_STRCASECMP
578 int strcasecmp(const char *s1, const char *s2);
579 #endif
580 #if !HAVE_DECL_STRNCASECMP
581 int strncasecmp(const char *s1, const char *s2, size_t n);
582 #endif
583 #if !HAVE_DECL_STRSIGNAL
584 char *strsignal(int sig);
585 #endif
586 #if !HAVE_DECL_STRDUP
587 char *strdup(const char *str);
588 #endif
589 #if !HAVE_DECL_MEMRCHR
590 void *memrchr(const void *s, int c, size_t n);
591 #endif
592 #if !HAVE_DECL_MEMDUP
593 void *memdup(const void *mem, size_t size);
594 #endif
595 #if !HAVE_DECL_MEMMEM
596 void *memmem(const void *haystack, size_t haystacklen,
597  const void *needle, size_t needlelen);
598 #endif
599 #if !HAVE_DECL_STRERROR
600 char *strerror(int err);
601 #endif
602 #if !HAVE_DECL_UNSETENV
603 int unsetenv(const char *name);
604 #endif
605 #ifndef HAVE_SETEUID
606 int seteuid(uid_t euid);
607 #endif
608 #ifndef HAVE_SETEUID
609 int setegid(gid_t egid);
610 #endif
611 #if !HAVE_DECL_SETLINEBUF
612 void setlinebuf(FILE *stream);
613 #endif
614 
615 #if HAVE_STDARG_H
616 # include <stdarg.h>
617 # if !HAVE_VSNPRINTF
618 int rpl_vsnprintf(char *, size_t, const char *, va_list);
619 /* If [v]snprintf() does not exist or is not C99 compatible, then we assume
620  * that [v]printf() and [v]fprintf() need to be provided as well. */
621 int rpl_vprintf(const char *format, va_list ap);
622 int rpl_vfprintf(FILE *stream, const char *format, va_list ap);
623 # endif
624 # if !HAVE_SNPRINTF
625 int rpl_snprintf(char *, size_t, const char *, ...);
626 int rpl_printf(const char *format, ...);
627 int rpl_fprintf(FILE *stream, const char *format, ...);
628 # endif
629 # if !HAVE_VASPRINTF
630 int rpl_vasprintf(char **, const char *, va_list);
631 # endif
632 # if !HAVE_ASPRINTF
633 int rpl_asprintf(char **, const char *, ...);
634 # endif
635 #endif /* HAVE_STDARG_H */
636 
637 /* For example Solaris, does not have isfinite() in <math.h>. */
638 #if !HAVE_DECL_ISFINITE && defined(HAVE_IEEEFP_H)
639 # include <ieeefp.h>
640 # define isfinite(x) finite(x)
641 #endif
642 
643 #if !HAVE_DECL_GETLINE
644 ssize_t getline(char **lineptr, size_t *n, FILE *stream);
645 #endif
646 #if !HAVE_DECL_STRCHRNUL
647 char *strchrnul(const char *s, int c);
648 #endif
649 #if !HAVE_DECL_GMTIME_R
650 struct tm *gmtime_r(const time_t *timep, struct tm *result);
651 #endif
652 #if !HAVE_DECL_LOCALTIME_R
653 struct tm *localtime_r(const time_t *timep, struct tm *result);
654 #endif
655 #if !HAVE_DECL_CHMOD
656 int chmod(const char *path, mode_t mode);
657 #endif
658 #if !HAVE_DECL_ALARM
659 unsigned int alarm(unsigned int seconds);
660 #endif
661 #if !HAVE_DECL_MKDTEMP
662 char *mkdtemp(char *template);
663 #endif
664 #if !HAVE_DECL_STRRSTR
665 char *strrstr(const char *haystack, const char *needle);
666 #endif
667 #if !HAVE_DECL_STPNCPY
668 char *stpncpy(char *dst, const char *src, size_t len);
669 #endif
670 #if !HAVE_DECL_INET_NTOP
671 const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
672 #endif
673 #if !HAVE_DECL_INET_PTON
674 int inet_pton(int af, const char *src, void *dst);
675 #endif
676 #if !HAVE_DECL_GETADDRINFO
677 int getaddrinfo(const char *node, const char *service,
678  const struct addrinfo *hints, struct addrinfo **res);
679 void freeaddrinfo(struct addrinfo *res);
680 int getnameinfo(const struct sockaddr *sa, socklen_t salen,
681  char *node, socklen_t nodelen,
682  char *service, socklen_t servicelen, int flags);
683 const char *gai_strerror(int errcode);
684 #endif
685 #if !HAVE_STRUCT_SOCKADDR_STORAGE
686  #ifdef AF_INET6
687  #define sockaddr_storage sockaddr_in6
688  #else
689  #define sockaddr_storage sockaddr
690  #endif
691 #endif
692 #ifndef AF_INET6
693  /* if the platform doesn't have it, it's useless, but define it as -1
694  * since we need it in our code... */
695  #define AF_INET6 -1
696 #endif
697 #ifndef AI_NUMERICSERV
698  /* Not portable to MinGW so don't use it. */
699  #define AI_NUMERICSERV -1
700 #endif
701 
702 #if !defined(HAVE_MKDIR_PROPER)
703 int rpl_mkdir(const char *pathname, mode_t mode);
704 #endif
705 
706 #if !defined(HAVE_STAT_PROPER)
707 int rpl_stat(const char *path, struct stat *buf);
708 #define _stat64(name, st) rpl_stat(name, st)
709 #endif
710 
711 #if !defined(HAVE_RENAME_PROPER)
712 int rpl_rename(const char *oldpath, const char *newpath);
713 #endif
714 
715 #if !defined(HAVE_CTIME_PROPER)
716 char *rpl_ctime(const time_t *t);
717 #endif
718 
719 #ifndef NGROUPS
720 # define NGROUPS 20
721 #endif
722 
723 #if !HAVE_DECL_OPENAT
724 int openat(int dirfd, const char *pathname, int flags, ...);
725 #endif
726 #if !HAVE_DECL_FSTATAT
727 int fstatat(int dirfd, const char *pathname, struct stat *buf, int flags);
728 #endif
729 #if !HAVE_DECL_FCHOWNAT
730 int fchownat(int dirfd, const char *pathname, uid_t owner, gid_t group, int flags);
731 #endif
732 #if !HAVE_DECL_FCHMODAT
733 int fchmodat(int dirfd, const char *pathname, mode_t mode, int flags);
734 #endif
735 #if !HAVE_DECL_READLINKAT
736 int readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz);
737 #endif
738 #ifndef AT_SYMLINK_NOFOLLOW
739 #define AT_SYMLINK_NOFOLLOW 0x1000
740 #endif
741 #ifndef AT_FDCWD
742 #define AT_FDCWD (-2)
743 #endif
744 
745 #if !HAVE_DECL_LOG2
746 double log2(double x);
747 #endif
748 
749 /*******************************************************************/
750 /* Windows */
751 /*******************************************************************/
752 
753 #ifdef __MINGW32__
754 # define MAXHOSTNAMELEN 256 // always adequate: http://msdn.microsoft.com/en-us/library/ms738527(VS.85).aspx
755 
756 // as seen in in_addr struct in winsock.h
757 typedef u_long in_addr_t;
758 
759 // shold be in winnt.h, but is not in current MinGW version
760 # ifndef VER_SUITE_WH_SERVER
761 # define VER_SUITE_WH_SERVER 0x00008000
762 # endif
763 
764 /* Dummy signals, can be set to anything below 23 but
765  * 2, 4, 8, 11, 15, 21, 22 which are taken.
766  * Calling signal() with anything from below causes SIG_ERR
767  * to be returned. */
768 
769 # define SIGALRM 1
770 # define SIGHUP 3
771 # define SIGTRAP 5
772 # define SIGKILL 6
773 # define SIGPIPE 7
774 # define SIGCONT 9
775 # define SIGSTOP 10
776 # define SIGQUIT 12
777 # define SIGCHLD 13
778 # define SIGUSR1 14
779 # define SIGUSR2 16
780 # define SIGBUS 17
781 
782 # if !defined( _TIMESPEC_DEFINED) && !defined(HAVE_STRUCT_TIMESPEC)
783 # define HAVE_STRUCT_TIMESPEC 1
784 struct timespec
785 {
786  long tv_sec;
787  long tv_nsec;
788 };
789 # endif/* NOT _TIMESPEC_DEFINED */
790 
791 #endif /* __MINGW32__ */
792 
793 #ifndef ERESTARTSYS
794 # define ERESTARTSYS EINTR
795 #endif
796 
797 #ifndef EOPNOTSUPP
798 # define EOPNOTSUPP EINVAL
799 #endif
800 
801 #ifndef ENOTSUPP
802 # define ENOTSUPP EINVAL
803 #endif
804 
805 #ifndef ENOLINK
806 // Should be well outside the range of any errno value.
807 // Will never actually be returned by any function on a platform that doesn't support it.
808 # define ENOLINK 123456
809 #endif
810 
811 /*******************************************************************/
812 /* Copy file defines */
813 /*******************************************************************/
814 
815 /**
816  * DEV_BSIZE is 512 for most common platforms
817  * (Linux, AIX on Power, Solaris etc).
818  *
819  * Exceptions:
820  * HP-UX: 1024
821  * AIX on PS/2: 4096
822  * Windows: undefined
823  */
824 #ifndef DEV_BSIZE /* usually defined in <sys/param.h> */
825 # ifdef BSIZE
826 # define DEV_BSIZE BSIZE
827 # else
828 # define DEV_BSIZE 512
829 # endif
830 #endif
831 
832 /**
833  Extract or fake data from a `struct stat'.
834  ST_BLKSIZE: Optimal I/O blocksize for the file, in bytes.
835  This is tightly coupled to ST_NBLOCKS, i.e it must stand that
836  (s.st_size <= ST_NBLOCKS(s) * ST_BLKSIZE(s))
837  ST_NBLOCKS: Number of blocks in the file, **in ST_BLKSIZE units**
838  WARNING this is different than "stat.st_nblocks" on most systems
839  ST_NBYTES : "disk usage" of the file on the disk, **in bytes**.
840 
841  TODO on Windows here is how to get the "cluster size" i.e. the block size:
842  - send IOCTL_DISK_GET_DRIVE_GEOMETRY_EX and use Geometry.BytesPerSector
843  from DISK_GEOMETRY_EX structure
844  - To check if a file is sparse: File.GetAttributes().SparseFile
845 */
846 
847 /*
848  * Known platforms that don't have stat.st_blocks:
849  * Windows (MinGW)
850  */
851 #ifndef HAVE_STRUCT_STAT_ST_BLOCKS
852 
853 
854 # define ST_BLKSIZE(statbuf) DEV_BSIZE
855 # define ST_NBLOCKS(statbuf) (((statbuf).st_size + DEV_BSIZE - 1) / DEV_BSIZE)
856 # define ST_NBYTES(statbuf) (ST_NBLOCKS(statbuf) * DEV_BSIZE)
857 
858 
859 #else /* HAVE_STRUCT_STAT_ST_BLOCKS */
860  /* Some systems, like Sequents, return st_blksize of 0 on pipes. */
861 # define ST_BLKSIZE(statbuf) ((statbuf).st_blksize > 0 \
862  ? (statbuf).st_blksize : DEV_BSIZE)
863 # define ST_NBLOCKS(statbuf) ((ST_NBYTES(statbuf) + ST_BLKSIZE(statbuf) - 1) \
864  / ST_BLKSIZE(statbuf))
865 
866 # if defined(_CRAY)
867 # define ST_NBYTES(statbuf) ((statbuf).st_blocks * ST_BLKSIZE(statbuf))
868 # else
869  /* ======= DEFAULT ============================== */
870  /* Most OS give stat.st_blocks in DEV_BSIZE units */
871 # define ST_NBYTES(statbuf) ((statbuf).st_blocks * DEV_BSIZE)
872  /* ============================================== */
873 # endif /* CRAY */
874 
875 
876 #endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
877 
878 
879 #ifndef SEEK_CUR
880 # define SEEK_CUR 1
881 #endif
882 
883 /*******************************************************************/
884 /* Ultrix/BSD don't have all these from sys/stat.h */
885 /*******************************************************************/
886 
887 #ifndef S_IFBLK
888 # define S_IFBLK 0060000
889 #endif
890 #ifndef S_IFCHR
891 # define S_IFCHR 0020000
892 #endif
893 #ifndef S_IFDIR
894 # define S_IFDIR 0040000
895 #endif
896 #ifndef S_IFIFO
897 # define S_IFIFO 0010000
898 #endif
899 #ifndef S_IFREG
900 # define S_IFREG 0100000
901 #endif
902 #ifndef S_IFLNK
903 # define S_IFLNK 0120000
904 #endif
905 #ifndef S_IFSOCK
906 # define S_IFSOCK 0140000
907 #endif
908 #ifndef S_IFMT
909 # define S_IFMT 00170000
910 #endif
911 
912 #ifndef S_ISREG
913 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
914 #endif
915 #ifndef S_ISDIR
916 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
917 #endif
918 #ifndef S_ISLNK
919 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
920 #endif
921 #ifndef S_ISFIFO
922 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
923 #endif
924 #ifndef S_ISCHR
925 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
926 #endif
927 #ifndef S_ISBLK
928 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
929 #endif
930 #ifndef S_ISSOCK
931 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
932 #endif
933 
934 #ifndef S_IRUSR
935 # define S_IRWXU 00700
936 # define S_IRUSR 00400
937 # define S_IWUSR 00200
938 # define S_IXUSR 00100
939 #endif
940 
941 #ifndef S_IRGRP
942 # define S_IRWXG 00070
943 # define S_IRGRP 00040
944 # define S_IWGRP 00020
945 # define S_IXGRP 00010
946 #endif
947 
948 #ifndef S_IROTH
949 # define S_IRWXO 00007
950 # define S_IROTH 00004
951 # define S_IWOTH 00002
952 # define S_IXOTH 00001
953 #endif
954 
955 /* kill(2) on OS X returns ETIMEDOUT instead of ESRCH */
956 #ifndef ETIMEDOUT
957 # define ETIMEDOUT ESRCH
958 #endif
959 
960 /* For getnameinfo(). */
961 #ifndef NI_MAXHOST
962 # define NI_MAXHOST 1025
963 #endif
964 
965 /********************************************************************/
966 /* *BSD chflags stuff - */
967 /********************************************************************/
968 
969 #if !defined UF_NODUMP
970 # define UF_NODUMP 0
971 #endif
972 #if !defined UF_IMMUTABLE
973 # define UF_IMMUTABLE 0
974 #endif
975 #if !defined UF_APPEND
976 # define UF_APPEND 0
977 #endif
978 #if !defined UF_OPAQUE
979 # define UF_OPAQUE 0
980 #endif
981 #if !defined UF_NOUNLINK
982 # define UF_NOUNLINK 0
983 #endif
984 #if !defined SF_ARCHIVED
985 # define SF_ARCHIVED 0
986 #endif
987 #if !defined SF_IMMUTABLE
988 # define SF_IMMUTABLE 0
989 #endif
990 #if !defined SF_APPEND
991 # define SF_APPEND 0
992 #endif
993 #if !defined SF_NOUNLINK
994 # define SF_NOUNLINK 0
995 #endif
996 #define CHFLAGS_MASK ( UF_NODUMP | UF_IMMUTABLE | UF_APPEND | UF_OPAQUE | UF_NOUNLINK | SF_ARCHIVED | SF_IMMUTABLE | SF_APPEND | SF_NOUNLINK )
997 
998 /* For cygwin32 */
999 
1000 #if !defined O_BINARY
1001 # define O_BINARY 0
1002 #endif
1003 
1004 #if !defined O_TEXT
1005 # define O_TEXT 0
1006 #endif
1007 
1008 #if defined(__MINGW32__)
1009 /* _mkdir(3) */
1010 # include <direct.h>
1011 #endif
1012 
1013 
1014 /* Some shorthands. */
1015 
1016 # if defined(__sun) && !defined(sun)
1017 # define sun
1018 # endif
1019 
1020 # if defined(__SVR4) && !defined(SVR4)
1021 # define SVR4
1022 # endif
1023 
1024 # if (defined(sun) && defined(SVR4)) || defined (SOLARIS2)
1025 # define SUNOS_5
1026 # endif
1027 
1028 #include <condition_macros.h>
1029 
1030 /* Must be always the last one! */
1031 #include <deprecated.h>
1032 #include <config.post.h>
1033 
1034 
1035 #endif /* CFENGINE_PLATFORM_H */
int getnetgrent(char **host, char **user, char **domain)
Definition: patches.c:60
size_t strlcpy(char *destination, const char *source, size_t size)
Definition: strlcpy.c:34
const char * inet_ntop(int af, const void *src, char *dst, socklen_t size)
Definition: inet_ntop.c:50
int clock_gettime(clockid_t clock_id, struct timespec *tp)
Definition: clock_gettime.c:30
char * strrstr(const char *haystack, const char *needle)
Definition: strrstr.c:43
int unsetenv(const char *name)
int openat(int dirfd, const char *pathname, int flags,...)
Definition: openat.c:60
int getloadavg(double loadavg[], int nelem)
int nanosleep(const struct timespec *req, struct timespec *rem)
int chown(const char *path, uid_t owner, gid_t group)
int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res)
Definition: getaddrinfo.c:262
int seteuid(uid_t euid)
Definition: seteuid.c:28
void setnetgrent(const char *netgroup)
Definition: patches.c:47
char * strdup(const char *str)
Definition: strdup.c:36
uid_t getuid(void)
char * rpl_ctime(const time_t *t)
Definition: rpl_ctime.c:30
double log2(double x)
Definition: log2.c:27
void setlinebuf(FILE *stream)
Definition: setlinebuf.c:47
int fchmod(int fd, mode_t mode)
void * memrchr(const void *s, int c, size_t n)
Definition: memrchr.c:32
struct tm * localtime_r(const time_t *timep, struct tm *result)
char * strchrnul(const char *s, int c)
Definition: strchrnul.c:9
void freeaddrinfo(struct addrinfo *res)
Definition: getaddrinfo.c:323
void srand48(long seed)
Definition: srand48.c:35
char * strstr(const char *haystack, const char *needle)
Definition: strstr.c:35
char * mkdtemp(char *template)
Definition: mkdtemp.c:30
int socketpair(int domain, int type, int protocol, int sv[2])
int fchownat(int dirfd, const char *pathname, uid_t owner, gid_t group, int flags)
Definition: fchownat.c:61
gid_t getgid(void)
void * memmem(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen)
Definition: memmem.c:31
int lstat(const char *file_name, struct stat *buf)
int strncasecmp(const char *s1, const char *s2, size_t n)
Definition: strncasecmp.c:33
unsigned int sleep(unsigned int seconds)
int socklen_t
Definition: platform.h:419
int clockid_t
Definition: platform.h:415
struct tm * gmtime_r(const time_t *timep, struct tm *result)
int strcasecmp(const char *s1, const char *s2)
Definition: strcasecmp.c:33
char * stpncpy(char *dst, const char *src, size_t len)
Definition: stpncpy.c:39
void endnetgrent(void)
Definition: patches.c:78
static uint32_t ByteSwap32(uint32_t le32uint)
Definition: platform.h:439
char * strerror(int err)
Definition: strerror.c:35
double round(double x)
Definition: round.c:35
int rpl_rename(const char *oldpath, const char *newpath)
int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
void * memdup(const void *mem, size_t size)
Definition: memdup.c:36
int dirfd(DIR *dirp)
int uname(struct utsname *buf)
char * strndup(const char *s, size_t n)
Definition: strndup.c:38
unsigned int alarm(unsigned int seconds)
char * strsignal(int sig)
Definition: strsignal.c:43
char * strsep(char **stringp, const char *delim)
Definition: strsep.c:53
int fchmodat(int dirfd, const char *pathname, mode_t mode, int flags)
Definition: fchmodat.c:60
int fsync(int fd)
void globfree(glob_t *pglob)
int closefrom(int fd)
Definition: closefrom.c:37
int glob(const char *pattern, int flags, int(*errfunc)(const char *epath, int eerrno), glob_t *pglob)
ssize_t getline(char **lineptr, size_t *n, FILE *stream)
int rpl_mkdir(const char *pathname, mode_t mode)
int chmod(const char *path, mode_t mode)
int rpl_stat(const char *path, struct stat *buf)
int readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz)
Definition: readlinkat.c:53
int inet_pton(int af, const char *src, void *dst)
Definition: inet_pton.c:51
const char * gai_strerror(int errcode)
Definition: getaddrinfo.c:340
int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *node, socklen_t nodelen, char *service, socklen_t servicelen, int flags)
Definition: getaddrinfo.c:476
size_t strnlen(const char *str, size_t maxlen)
Definition: strnlen.c:32
size_t strlcat(char *destination, const char *source, size_t size)
Definition: strlcat.c:36
int fstatat(int dirfd, const char *pathname, struct stat *buf, int flags)
Definition: fstatat.c:60
struct group * fgetgrent(FILE *stream)
char * strcasestr(const char *haystack, const char *needle)
Definition: strcasestr.c:36
int setegid(gid_t gid)
Definition: patches.c:91
double drand48(void)
Definition: drand48.c:36
#define _SYS_NMLN
Definition: platform.h:104
int rpl_vsnprintf(char *str, size_t size, const char *format, va_list args)
Definition: snprintf.c:539
int rpl_vprintf(const char *format, va_list ap)
Definition: snprintf.c:1617
int rpl_asprintf(va_alist)
Definition: snprintf.c:1547
int rpl_snprintf(va_alist)
Definition: snprintf.c:1520
int rpl_fprintf(FILE *stream, const char *format,...)
Definition: snprintf.c:1631
int rpl_printf(const char *format,...)
Definition: snprintf.c:1642
int rpl_vfprintf(FILE *stream, const char *format, va_list ap)
Definition: snprintf.c:1571
int rpl_vasprintf(char **ret, const char *format, va_list ap)
Definition: snprintf.c:1499
size_t gl_pathc
Definition: platform.h:281
char ** gl_pathv
Definition: platform.h:282
size_t gl_offs
Definition: platform.h:283
char version[257]
Definition: platform.h:111
char sysname[257]
Definition: platform.h:108
char nodename[257]
Definition: platform.h:109
char release[257]
Definition: platform.h:110
char machine[257]
Definition: platform.h:112