/src/gnupg/common/sysutils.h
Line | Count | Source |
1 | | /* sysutils.h - System utility functions for Gnupg |
2 | | * Copyright (C) 2002 Free Software Foundation, Inc. |
3 | | * |
4 | | * This file is part of GnuPG. |
5 | | * |
6 | | * This file is free software; you can redistribute it and/or modify |
7 | | * it under the terms of either |
8 | | * |
9 | | * - the GNU Lesser General Public License as published by the Free |
10 | | * Software Foundation; either version 3 of the License, or (at |
11 | | * your option) any later version. |
12 | | * |
13 | | * or |
14 | | * |
15 | | * - the GNU General Public License as published by the Free |
16 | | * Software Foundation; either version 2 of the License, or (at |
17 | | * your option) any later version. |
18 | | * |
19 | | * or both in parallel, as here. |
20 | | * |
21 | | * This file is distributed in the hope that it will be useful, |
22 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
23 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24 | | * GNU General Public License for more details. |
25 | | * |
26 | | * You should have received a copy of the GNU General Public License |
27 | | * along with this program; if not, see <https://www.gnu.org/licenses/>. |
28 | | */ |
29 | | |
30 | | #ifndef GNUPG_COMMON_SYSUTILS_H |
31 | | #define GNUPG_COMMON_SYSUTILS_H |
32 | | |
33 | | /* Because we use system handles and not libc low level file |
34 | | descriptors on W32, we need to declare them as HANDLE (which |
35 | | actually is a plain pointer). This is required to eventually |
36 | | support 64 bits Windows systems. */ |
37 | | #ifdef HAVE_W32_SYSTEM |
38 | | typedef void *gnupg_fd_t; |
39 | | #define GNUPG_INVALID_FD ((void*)(-1)) |
40 | | #define INT2FD(s) ((void *)(s)) |
41 | | # ifdef _WIN64 |
42 | | # define FD2INT(h) ((intptr_t)(h)) |
43 | | # else |
44 | | # define FD2INT(h) ((unsigned int)(h)) |
45 | | # endif |
46 | | #define FD_DBG(h) ((int)(intptr_t)(h)) |
47 | | #define FD2NUM(h) ((int)(intptr_t)(h)) |
48 | | #else |
49 | | typedef int gnupg_fd_t; |
50 | 51.1k | #define GNUPG_INVALID_FD (-1) |
51 | | #define INT2FD(s) (s) |
52 | | #define FD2INT(h) (h) |
53 | 0 | #define FD_DBG(h) (h) |
54 | | #define FD2NUM(h) (h) |
55 | | #endif |
56 | | |
57 | | #ifdef HAVE_STAT |
58 | | # include <sys/stat.h> |
59 | | #endif |
60 | | |
61 | | struct gnupg_dir_s; |
62 | | typedef struct gnupg_dir_s *gnupg_dir_t; |
63 | | struct gnupg_dirent_s |
64 | | { |
65 | | /* We don't have a d_ino because that can't be used on Windows |
66 | | * anyway. D_NAME is a pointer into the gnupg_dir_s which has a |
67 | | * static buffer or allocates sufficient space as needed. This is |
68 | | * only valid after gnupg_readdir. */ |
69 | | char *d_name; |
70 | | }; |
71 | | typedef struct gnupg_dirent_s *gnupg_dirent_t; |
72 | | |
73 | | |
74 | | void trap_unaligned (void); |
75 | | int disable_core_dumps (void); |
76 | | int enable_core_dumps (void); |
77 | | void enable_special_filenames (void); |
78 | | void disable_translate_sys2libc_fd (void); |
79 | | |
80 | | const unsigned char *get_session_marker (size_t *rlen); |
81 | | unsigned int get_uint_nonce (void); |
82 | | /*int check_permissions (const char *path,int extension,int checkonly);*/ |
83 | | void gnupg_sleep (unsigned int seconds); |
84 | | void gnupg_usleep (unsigned int usecs); |
85 | | int translate_sys2libc_fd_int (int fd, int for_write); |
86 | | gpg_error_t gnupg_parse_fdstr (const char *fdstr, es_syshd_t *r_syshd); |
87 | | int check_special_filename (const char *fname, int for_write, int notranslate); |
88 | | gnupg_fd_t gnupg_check_special_filename (const char *fname); |
89 | | FILE *gnupg_tmpfile (void); |
90 | | void gnupg_reopen_std (const char *pgmname); |
91 | | void gnupg_inhibit_set_foregound_window (int yes); |
92 | | void gnupg_allow_set_foregound_window (pid_t pid); |
93 | | int gnupg_remove_ext (const char *fname, int wait_for_access); |
94 | | int gnupg_remove (const char *fname); |
95 | | gpg_error_t gnupg_rename_file (const char *oldname, const char *newname, |
96 | | int *block_signals); |
97 | | int gnupg_mkdir (const char *name, const char *modestr); |
98 | | int gnupg_chdir (const char *name); |
99 | | int gnupg_rmdir (const char *name); |
100 | | int gnupg_chmod (const char *name, const char *modestr); |
101 | | char *gnupg_mkdtemp (char *template); |
102 | | int gnupg_setenv (const char *name, const char *value, int overwrite); |
103 | | int gnupg_unsetenv (const char *name); |
104 | | char *gnupg_getcwd (void); |
105 | | gpg_err_code_t gnupg_access (const char *name, int mode); |
106 | | #ifdef HAVE_STAT |
107 | | int gnupg_stat (const char *name, struct stat *statbuf); |
108 | | #endif /*HAVE_STAT*/ |
109 | | int gnupg_open (const char *name, int flags, unsigned int mode); |
110 | | |
111 | | gnupg_dir_t gnupg_opendir (const char *name); |
112 | | gnupg_dirent_t gnupg_readdir (gnupg_dir_t gdir); |
113 | | int gnupg_closedir (gnupg_dir_t gdir); |
114 | | |
115 | | gpg_error_t gnupg_chuid (const char *user, int silent); |
116 | | char *gnupg_get_socket_name (int fd); |
117 | | int gnupg_fd_valid (int fd); |
118 | | |
119 | | gpg_error_t gnupg_inotify_watch_delete_self (int *r_fd, const char *fname); |
120 | | gpg_error_t gnupg_inotify_watch_socket (int *r_fd, const char *socket_name); |
121 | | int gnupg_inotify_has_name (int fd, const char *name); |
122 | | |
123 | | estream_t open_stream_nc (gnupg_fd_t fd, const char *mode); |
124 | | |
125 | | void output_debug_string (const char *format, ...) GPGRT_ATTR_PRINTF(1,2); |
126 | | |
127 | | #ifdef HAVE_W32_SYSTEM |
128 | | int gnupg_w32_set_errno (int ec); |
129 | | void *w32_get_user_sid (void); |
130 | | |
131 | | #include "../common/w32help.h" |
132 | | |
133 | | #endif /*HAVE_W32_SYSTEM*/ |
134 | | |
135 | | #endif /*GNUPG_COMMON_SYSUTILS_H*/ |