diff options
Diffstat (limited to 'lib-src')
-rw-r--r-- | lib-src/Makefile.in | 7 | ||||
-rw-r--r-- | lib-src/ebrowse.c | 11 | ||||
-rw-r--r-- | lib-src/emacsclient.c | 39 | ||||
-rw-r--r-- | lib-src/etags.c | 350 | ||||
-rw-r--r-- | lib-src/hexl.c | 2 | ||||
-rw-r--r-- | lib-src/make-docfile.c | 6 | ||||
-rw-r--r-- | lib-src/movemail.c | 4 | ||||
-rw-r--r-- | lib-src/ntlib.c | 22 | ||||
-rw-r--r-- | lib-src/ntlib.h | 3 | ||||
-rw-r--r-- | lib-src/pop.c | 223 | ||||
-rw-r--r-- | lib-src/profile.c | 5 | ||||
-rw-r--r-- | lib-src/update-game-score.c | 1 |
12 files changed, 489 insertions, 184 deletions
diff --git a/lib-src/Makefile.in b/lib-src/Makefile.in index 2aaec25a5a3..c3693abf341 100644 --- a/lib-src/Makefile.in +++ b/lib-src/Makefile.in @@ -345,9 +345,12 @@ extraclean: maintainer-clean check: @echo "We don't have any tests for the lib-src/ directory yet." +tagsfiles = $(wildcard ${srcdir}/*.[ch]) + +.PHONY: tags tags: TAGS -TAGS: etags${EXEEXT} - etags *.[ch] +TAGS: etags${EXEEXT} ${tagsfiles} + ./etags ${tagsfiles} ../lib/libgnu.a: $(config_h) $(MAKE) -C ../lib all diff --git a/lib-src/ebrowse.c b/lib-src/ebrowse.c index c59181f9464..7a262005df9 100644 --- a/lib-src/ebrowse.c +++ b/lib-src/ebrowse.c @@ -32,6 +32,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #define SEEK_END 2 #endif +#include <flexmember.h> #include <min-max.h> /* Files are read in chunks of this number of bytes. */ @@ -582,7 +583,7 @@ add_sym (const char *name, struct sym *nested_in_class) puts (name); } - sym = xmalloc (offsetof (struct sym, name) + strlen (name) + 1); + sym = xmalloc (FLEXSIZEOF (struct sym, name, strlen (name) + 1)); memset (sym, 0, offsetof (struct sym, name)); strcpy (sym->name, name); sym->namesp = scope; @@ -867,8 +868,8 @@ add_global_decl (char *name, char *regexp, int pos, unsigned int hash, int var, static struct member * add_member (struct sym *cls, char *name, int var, int sc, unsigned int hash) { - struct member *m = xmalloc (offsetof (struct member, name) - + strlen (name) + 1); + struct member *m = xmalloc (FLEXSIZEOF (struct member, name, + strlen (name) + 1)); struct member **list; struct member *p; struct member *prev; @@ -978,7 +979,7 @@ mark_inherited_virtual (void) static struct sym * make_namespace (char *name, struct sym *context) { - struct sym *s = xmalloc (offsetof (struct sym, name) + strlen (name) + 1); + struct sym *s = xmalloc (FLEXSIZEOF (struct sym, name, strlen (name) + 1)); memset (s, 0, offsetof (struct sym, name)); strcpy (s->name, name); s->next = all_namespaces; @@ -1062,7 +1063,7 @@ register_namespace_alias (char *new_name, struct link *old_name) if (streq (new_name, al->name) && (al->namesp == current_namespace)) return; - al = xmalloc (offsetof (struct alias, name) + strlen (new_name) + 1); + al = xmalloc (FLEXSIZEOF (struct alias, name, strlen (new_name) + 1)); strcpy (al->name, new_name); al->next = namespace_alias_table[h]; al->namesp = current_namespace; diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index dd66d34da70..2909d6392a7 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -39,7 +39,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ # define CLOSE_SOCKET closesocket # define INITIALIZE() (initialize_sockets ()) -char *w32_getenv (char *); +char *w32_getenv (const char *); #define egetenv(VAR) w32_getenv(VAR) #else /* !WINDOWSNT */ @@ -74,6 +74,8 @@ char *w32_getenv (char *); #include <stdarg.h> #include <ctype.h> #include <stdio.h> +#include <stdlib.h> +#include <string.h> #include <getopt.h> #include <unistd.h> @@ -254,6 +256,7 @@ get_current_dir_name (void) #ifdef WINDOWSNT /* Like strdup but get a fatal error if memory is exhausted. */ +char *xstrdup (const char *); char * xstrdup (const char *s) @@ -269,11 +272,13 @@ xstrdup (const char *s) #define REG_ROOT "SOFTWARE\\GNU\\Emacs" +char *w32_get_resource (HKEY, const char *, LPDWORD); + /* Retrieve an environment variable from the Emacs subkeys of the registry. Return NULL if the variable was not found, or it was empty. This code is based on w32_get_resource (w32.c). */ char * -w32_get_resource (HKEY predefined, char *key, LPDWORD type) +w32_get_resource (HKEY predefined, const char *key, LPDWORD type) { HKEY hrootkey = NULL; char *result = NULL; @@ -285,7 +290,7 @@ w32_get_resource (HKEY predefined, char *key, LPDWORD type) { result = (char *) xmalloc (cbData); - if ((RegQueryValueEx (hrootkey, key, NULL, type, result, &cbData) != ERROR_SUCCESS) + if ((RegQueryValueEx (hrootkey, key, NULL, type, (LPBYTE)result, &cbData) != ERROR_SUCCESS) || (*result == 0)) { free (result); @@ -308,7 +313,7 @@ w32_get_resource (HKEY predefined, char *key, LPDWORD type) environment variables in the registry if they don't appear in the environment. */ char * -w32_getenv (char *envvar) +w32_getenv (const char *envvar) { char *value; DWORD dwType; @@ -356,6 +361,7 @@ w32_getenv (char *envvar) return NULL; } +int w32_window_app (void); int w32_window_app (void) @@ -383,11 +389,12 @@ w32_window_app (void) predictably bad results. By contrast, POSIX execvp passes the arguments directly into the argv array of the child process. */ +int w32_execvp (const char *, char **); + int w32_execvp (const char *path, char **argv) { int i; - extern int execvp (const char*, char **); /* Required to allow a .BAT script as alternate editor. */ argv[0] = (char *) alternate_editor; @@ -407,7 +414,8 @@ w32_execvp (const char *path, char **argv) #define execvp w32_execvp /* Emulation of ttyname for Windows. */ -char * +const char *ttyname (int); +const char * ttyname (int fd) { return "CONOUT$"; @@ -852,6 +860,7 @@ file_name_absolute_p (const char *filename) #ifdef WINDOWSNT /* Wrapper to make WSACleanup a cdecl, as required by atexit. */ +void __cdecl close_winsock (void); void __cdecl close_winsock (void) { @@ -859,6 +868,7 @@ close_winsock (void) } /* Initialize the WinSock2 library. */ +void initialize_sockets (void); void initialize_sockets (void) { @@ -1183,10 +1193,9 @@ set_local_socket (const char *local_socket_name) { int sock_status; - int use_tmpdir = 0; int saved_errno; const char *server_name = local_socket_name; - const char *tmpdir IF_LINT ( = NULL); + const char *tmpdir = NULL; char *tmpdir_storage = NULL; char *socket_name_storage = NULL; @@ -1194,7 +1203,6 @@ set_local_socket (const char *local_socket_name) { /* socket_name is a file name component. */ long uid = geteuid (); - use_tmpdir = 1; tmpdir = egetenv ("TMPDIR"); if (!tmpdir) { @@ -1232,7 +1240,7 @@ set_local_socket (const char *local_socket_name) /* See if the socket exists, and if it's owned by us. */ sock_status = socket_status (server.sun_path); saved_errno = errno; - if (sock_status && use_tmpdir) + if (sock_status && tmpdir) { /* Failing that, see if LOGNAME or USER exist and differ from our euid. If so, look for a socket based on the UID @@ -1380,11 +1388,13 @@ set_socket (int no_exit_if_error) FARPROC set_fg; /* Pointer to AllowSetForegroundWindow. */ FARPROC get_wc; /* Pointer to RealGetWindowClassA. */ +void w32_set_user_model_id (void); + void w32_set_user_model_id (void) { HMODULE shell; - HRESULT (WINAPI * set_user_model) (wchar_t * id); + HRESULT (WINAPI * set_user_model) (const wchar_t * id); /* On Windows 7 and later, we need to set the user model ID to associate emacsclient launched files with Emacs frames @@ -1407,6 +1417,8 @@ w32_set_user_model_id (void) } } +BOOL CALLBACK w32_find_emacs_process (HWND, LPARAM); + BOOL CALLBACK w32_find_emacs_process (HWND hWnd, LPARAM lParam) { @@ -1433,6 +1445,7 @@ w32_find_emacs_process (HWND hWnd, LPARAM lParam) /* Search for a window of class "Emacs" and owned by a process with process id = emacs_pid. If found, allow it to grab the focus. */ +void w32_give_focus (void); void w32_give_focus (void) @@ -1526,7 +1539,7 @@ start_daemon_and_retry_set_socket (void) it is ready to accept client connections, by asserting an event whose name is known to the daemon (defined by nt/inc/ms-w32.h). */ - if (!CreateProcess (NULL, "emacs --daemon", NULL, NULL, FALSE, + if (!CreateProcess (NULL, (LPSTR)"emacs --daemon", NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) { char* msg = NULL; @@ -1548,7 +1561,7 @@ start_daemon_and_retry_set_socket (void) if ((wait_result = WaitForSingleObject (w32_daemon_event, INFINITE)) != WAIT_OBJECT_0) { - char *msg = NULL; + const char *msg = NULL; switch (wait_result) { diff --git a/lib-src/etags.c b/lib-src/etags.c index 1457700fedd..7baa2a3e39f 100644 --- a/lib-src/etags.c +++ b/lib-src/etags.c @@ -90,10 +90,6 @@ char pot_etags_version[] = "@(#) pot revision number is 17.38.1.4"; #include <config.h> -#ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 /* enables some compiler checks on GNU */ -#endif - /* WIN32_NATIVE is for XEmacs. MSDOS, WINDOWSNT, DOS_NT are for Emacs. */ #ifdef WIN32_NATIVE @@ -112,7 +108,6 @@ char pot_etags_version[] = "@(#) pot revision number is 17.38.1.4"; #ifdef WINDOWSNT # include <direct.h> -# define MAXPATHLEN _MAX_PATH # undef HAVE_NTGUI # undef DOS_NT # define DOS_NT @@ -1335,7 +1330,7 @@ main (int argc, char **argv) pfatal (tagfile); } - exit (EXIT_SUCCESS); + return EXIT_SUCCESS; } /* From here on, we are in (CTAGS && !cxref_style) */ @@ -1343,7 +1338,7 @@ main (int argc, char **argv) { char *cmd = xmalloc (strlen (tagfile) + whatlen_max + - sizeof "mv..OTAGS;fgrep -v '\t\t' OTAGS >;rm OTAGS"); + sizeof "mv..OTAGS;grep -Fv '\t\t' OTAGS >;rm OTAGS"); for (i = 0; i < current_arg; ++i) { switch (argbuffer[i].arg_type) @@ -1356,7 +1351,7 @@ main (int argc, char **argv) } char *z = stpcpy (cmd, "mv "); z = stpcpy (z, tagfile); - z = stpcpy (z, " OTAGS;fgrep -v '\t"); + z = stpcpy (z, " OTAGS;grep -Fv '\t"); z = stpcpy (z, argbuffer[i].what); z = stpcpy (z, "\t' OTAGS >"); z = stpcpy (z, tagfile); @@ -1388,7 +1383,7 @@ main (int argc, char **argv) z = stpcpy (z, tagfile); *z++ = ' '; strcpy (z, tagfile); - exit (system (cmd)); + return system (cmd); } return EXIT_SUCCESS; } @@ -2007,19 +2002,78 @@ pfnote (char *name, bool is_func, char *linestart, int linelen, int lno, } /* + * Utility functions and data to avoid recursion. + */ + +typedef struct stack_entry { + node *np; + struct stack_entry *next; +} stkentry; + +static void +push_node (node *np, stkentry **stack_top) +{ + if (np) + { + stkentry *new = xnew (1, stkentry); + + new->np = np; + new->next = *stack_top; + *stack_top = new; + } +} + +static node * +pop_node (stkentry **stack_top) +{ + node *ret = NULL; + + if (*stack_top) + { + stkentry *old_start = *stack_top; + + ret = (*stack_top)->np; + *stack_top = (*stack_top)->next; + free (old_start); + } + return ret; +} + +/* * free_tree () - * recurse on left children, iterate on right children. + * emulate recursion on left children, iterate on right children. */ static void free_tree (register node *np) { + stkentry *stack = NULL; + while (np) { - register node *node_right = np->right; - free_tree (np->left); + /* Descent on left children. */ + while (np->left) + { + push_node (np, &stack); + np = np->left; + } + /* Free node without left children. */ + node *node_right = np->right; free (np->name); free (np->regex); free (np); + if (!node_right) + { + /* Backtrack to find a node with right children, while freeing nodes + that don't have right children. */ + while (node_right == NULL && (np = pop_node (&stack)) != NULL) + { + node_right = np->right; + free (np->name); + free (np->regex); + free (np); + } + } + /* Free right children. */ np = node_right; } } @@ -2051,9 +2105,9 @@ free_fdesc (register fdesc *fdp) static void add_node (node *np, node **cur_node_p) { - register int dif; - register node *cur_node = *cur_node_p; + node *cur_node = *cur_node_p; + /* Make the first node. */ if (cur_node == NULL) { *cur_node_p = np; @@ -2075,51 +2129,76 @@ add_node (node *np, node **cur_node_p) last_node->right = np; last_node = np; } - else if (cur_node->fdp == np->fdp) + else { - /* Scanning the list we found the head of a sublist which is - good for us. Let's scan this sublist. */ - add_node (np, &cur_node->right); + while (cur_node->fdp != np->fdp) + { + if (cur_node->left == NULL) + break; + /* The head of this sublist is not good for us. Let's try the + next one. */ + cur_node = cur_node->left; + } + if (cur_node->left) + { + /* Scanning the list we found the head of a sublist which is + good for us. Let's scan this sublist. */ + if (cur_node->right) + { + cur_node = cur_node->right; + while (cur_node->right) + cur_node = cur_node->right; + } + /* Make a new node in this sublist. */ + cur_node->right = np; + } + else + { + /* Make a new sublist. */ + cur_node->left = np; + } + last_node = np; } - else - /* The head of this sublist is not good for us. Let's try the - next one. */ - add_node (np, &cur_node->left); } /* if ETAGS mode */ - else { /* Ctags Mode */ - dif = strcmp (np->name, cur_node->name); + node **next_node = &cur_node; - /* - * If this tag name matches an existing one, then - * do not add the node, but maybe print a warning. - */ - if (no_duplicates && !dif) + while ((cur_node = *next_node) != NULL) { - if (np->fdp == cur_node->fdp) + int dif = strcmp (np->name, cur_node->name); + /* + * If this tag name matches an existing one, then + * do not add the node, but maybe print a warning. + */ + if (!dif && no_duplicates) { - if (!no_warnings) + if (np->fdp == cur_node->fdp) { - fprintf (stderr, "Duplicate entry in file %s, line %d: %s\n", - np->fdp->infname, lineno, np->name); - fprintf (stderr, "Second entry ignored\n"); + if (!no_warnings) + { + fprintf (stderr, + "Duplicate entry in file %s, line %d: %s\n", + np->fdp->infname, lineno, np->name); + fprintf (stderr, "Second entry ignored\n"); + } } + else if (!cur_node->been_warned && !no_warnings) + { + fprintf + (stderr, + "Duplicate entry in files %s and %s: %s (Warning only)\n", + np->fdp->infname, cur_node->fdp->infname, np->name); + cur_node->been_warned = true; + } + return; } - else if (!cur_node->been_warned && !no_warnings) - { - fprintf - (stderr, - "Duplicate entry in files %s and %s: %s (Warning only)\n", - np->fdp->infname, cur_node->fdp->infname, np->name); - cur_node->been_warned = true; - } - return; + else + next_node = dif < 0 ? &cur_node->left : &cur_node->right; } - - /* Actually add the node */ - add_node (np, dif < 0 ? &cur_node->left : &cur_node->right); + *next_node = np; + last_node = np; } /* if CTAGS mode */ } @@ -2132,31 +2211,66 @@ static void invalidate_nodes (fdesc *badfdp, node **npp) { node *np = *npp; - - if (np == NULL) - return; + stkentry *stack = NULL; if (CTAGS) { - if (np->left != NULL) - invalidate_nodes (badfdp, &np->left); - if (np->fdp == badfdp) - np->valid = false; - if (np->right != NULL) - invalidate_nodes (badfdp, &np->right); + while (np) + { + /* Push all the left children on the stack. */ + while (np->left != NULL) + { + push_node (np, &stack); + np = np->left; + } + /* Invalidate this node. */ + if (np->fdp == badfdp) + np->valid = false; + if (!np->right) + { + /* Pop nodes from stack, invalidating them, until we find one + with a right child. */ + while ((np = pop_node (&stack)) != NULL) + { + if (np->fdp == badfdp) + np->valid = false; + if (np->right != NULL) + break; + } + } + /* Process the right child, if any. */ + if (np) + np = np->right; + } } else { - assert (np->fdp != NULL); - if (np->fdp == badfdp) + node super_root, *np_parent = NULL; + + super_root.left = np; + super_root.fdp = (fdesc *) -1; + np = &super_root; + + while (np) { - *npp = np->left; /* detach the sublist from the list */ - np->left = NULL; /* isolate it */ - free_tree (np); /* free it */ - invalidate_nodes (badfdp, npp); + /* Descent on left children until node with BADFP. */ + while (np && np->fdp != badfdp) + { + assert (np->fdp != NULL); + np_parent = np; + np = np->left; + } + if (np) + { + np_parent->left = np->left; /* detach subtree from the tree */ + np->left = NULL; /* isolate it */ + free_tree (np); /* free it */ + + /* Continue with rest of tree. */ + np = np_parent->left; + } } - else - invalidate_nodes (badfdp, &np->left); + *npp = super_root.left; } } @@ -2201,18 +2315,11 @@ total_size_of_entries (register node *np) } static void -put_entries (register node *np) +put_entry (node *np) { register char *sp; static fdesc *fdp = NULL; - if (np == NULL) - return; - - /* Output subentries that precede this one */ - if (CTAGS) - put_entries (np->left); - /* Output this entry */ if (np->valid) { @@ -2278,11 +2385,59 @@ put_entries (register node *np) } } } /* if this node contains a valid tag */ +} - /* Output subentries that follow this one */ - put_entries (np->right); - if (!CTAGS) - put_entries (np->left); +static void +put_entries (node *np) +{ + stkentry *stack = NULL; + + if (np == NULL) + return; + + if (CTAGS) + { + while (np) + { + /* Stack subentries that precede this one. */ + while (np->left) + { + push_node (np, &stack); + np = np->left; + } + /* Output this subentry. */ + put_entry (np); + /* Stack subentries that follow this one. */ + while (!np->right) + { + /* Output subentries that precede the next one. */ + np = pop_node (&stack); + if (!np) + break; + put_entry (np); + } + if (np) + np = np->right; + } + } + else + { + push_node (np, &stack); + while ((np = pop_node (&stack)) != NULL) + { + /* Output this subentry. */ + put_entry (np); + while (np->right) + { + /* Output subentries that follow this one. */ + put_entry (np->right); + /* Stack subentries from the following files. */ + push_node (np->left, &stack); + np = np->right; + } + push_node (np->left, &stack); + } + } } @@ -4084,13 +4239,13 @@ Yacc_entries (FILE *inf) ((assert ("" kw), true) /* syntax error if not a literal string */ \ && strneq ((cp), kw, sizeof (kw)-1) /* cp points at kw */ \ && notinname ((cp)[sizeof (kw)-1]) /* end of kw */ \ - && ((cp) = skip_spaces ((cp)+sizeof (kw)-1))) /* skip spaces */ + && ((cp) = skip_spaces ((cp) + sizeof (kw) - 1), true)) /* skip spaces */ /* Similar to LOOKING_AT but does not use notinname, does not skip */ #define LOOKING_AT_NOCASE(cp, kw) /* the keyword is a literal string */ \ ((assert ("" kw), true) /* syntax error if not a literal string */ \ && strncaseeq ((cp), kw, sizeof (kw)-1) /* cp points at kw */ \ - && ((cp) += sizeof (kw)-1)) /* skip spaces */ + && ((cp) += sizeof (kw) - 1, true)) /* skip spaces */ /* * Read a file, but do no processing. This is used to do regexp @@ -5314,16 +5469,37 @@ Forth_words (FILE *inf) do /* skip to ) or eol */ bp++; while (*bp != ')' && *bp != '\0'); - else if ((bp[0] == ':' && c_isspace (bp[1]) && bp++) - || LOOKING_AT_NOCASE (bp, "constant") - || LOOKING_AT_NOCASE (bp, "code") - || LOOKING_AT_NOCASE (bp, "create") - || LOOKING_AT_NOCASE (bp, "defer") - || LOOKING_AT_NOCASE (bp, "value") - || LOOKING_AT_NOCASE (bp, "variable") - || LOOKING_AT_NOCASE (bp, "buffer:") - || LOOKING_AT_NOCASE (bp, "field")) - get_tag (skip_spaces (bp), NULL); /* Yay! A definition! */ + else if (((bp[0] == ':' && c_isspace (bp[1]) && bp++) + || LOOKING_AT_NOCASE (bp, "constant") + || LOOKING_AT_NOCASE (bp, "2constant") + || LOOKING_AT_NOCASE (bp, "fconstant") + || LOOKING_AT_NOCASE (bp, "code") + || LOOKING_AT_NOCASE (bp, "create") + || LOOKING_AT_NOCASE (bp, "defer") + || LOOKING_AT_NOCASE (bp, "value") + || LOOKING_AT_NOCASE (bp, "2value") + || LOOKING_AT_NOCASE (bp, "fvalue") + || LOOKING_AT_NOCASE (bp, "variable") + || LOOKING_AT_NOCASE (bp, "2variable") + || LOOKING_AT_NOCASE (bp, "fvariable") + || LOOKING_AT_NOCASE (bp, "buffer:") + || LOOKING_AT_NOCASE (bp, "field:") + || LOOKING_AT_NOCASE (bp, "+field") + || LOOKING_AT_NOCASE (bp, "field") /* not standard? */ + || LOOKING_AT_NOCASE (bp, "begin-structure") + || LOOKING_AT_NOCASE (bp, "synonym") + ) + && c_isspace (bp[0])) + { + /* Yay! A definition! */ + char* name_start = skip_spaces (bp); + char* name_end = skip_non_spaces (name_start); + if (name_start < name_end) + make_tag (name_start, name_end - name_start, + true, lb.buffer, name_end - lb.buffer, + lineno, linecharno); + bp = name_end; + } else bp = skip_non_spaces (bp); } diff --git a/lib-src/hexl.c b/lib-src/hexl.c index 9a5ca7e1543..5bd8579d258 100644 --- a/lib-src/hexl.c +++ b/lib-src/hexl.c @@ -22,6 +22,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <stdio.h> +#include <stdlib.h> +#include <string.h> #include <ctype.h> #include <binary-io.h> diff --git a/lib-src/make-docfile.c b/lib-src/make-docfile.c index 32e3817a465..9ba9b6e9af8 100644 --- a/lib-src/make-docfile.c +++ b/lib-src/make-docfile.c @@ -37,11 +37,11 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <stdarg.h> -#include <stdbool.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> -#include <stdlib.h> /* config.h unconditionally includes this anyway */ +#include <stdlib.h> +#include <string.h> #ifdef WINDOWSNT /* Defined to be sys_fopen in ms-w32.h, but only #ifdef emacs, so this @@ -491,7 +491,7 @@ write_c_args (char *func, char *buf, int minargs, int maxargs) { char *p; bool in_ident = false; - char *ident_start IF_LINT (= NULL); + char *ident_start UNINIT; ptrdiff_t ident_length = 0; fputs ("(fn", stdout); diff --git a/lib-src/movemail.c b/lib-src/movemail.c index 90e683ed855..8111c8721bb 100644 --- a/lib-src/movemail.c +++ b/lib-src/movemail.c @@ -59,8 +59,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <sys/types.h> #include <sys/stat.h> #include <sys/file.h> -#include <stdbool.h> #include <stdio.h> +#include <stdlib.h> #include <errno.h> #include <time.h> @@ -338,7 +338,7 @@ main (int argc, char **argv) int lockcount = 0; int status = 0; #if defined (MAIL_USE_MAILLOCK) && defined (HAVE_TOUCHLOCK) - time_t touched_lock IF_LINT (= 0); + time_t touched_lock; #endif if (setuid (getuid ()) < 0 || setregid (-1, real_gid) < 0) diff --git a/lib-src/ntlib.c b/lib-src/ntlib.c index 4b25796830e..2ac021936ae 100644 --- a/lib-src/ntlib.c +++ b/lib-src/ntlib.c @@ -34,6 +34,12 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include "ntlib.h" +char *sys_ctime (const time_t *); +FILE *sys_fopen (const char *, const char *); +int sys_chdir (const char *); +int mkostemp (char *, int); +int sys_rename (const char *, const char *); + /* MinGW64 defines _TIMEZONE_DEFINED and defines 'struct timespec' in its system headers. */ #ifndef _TIMEZONE_DEFINED @@ -44,6 +50,8 @@ struct timezone }; #endif +void gettimeofday (struct timeval *, struct timezone *); + #define MAXPATHLEN _MAX_PATH /* Emulate sleep...we could have done this with a define, but that @@ -90,7 +98,7 @@ getppid (void) getppid_parent = OpenProcess (SYNCHRONIZE, FALSE, atoi (ppid)); if (!getppid_parent) { - printf ("Failed to open handle to parent process: %d\n", + printf ("Failed to open handle to parent process: %lu\n", GetLastError ()); exit (1); } @@ -107,7 +115,7 @@ getppid (void) return 1; case WAIT_FAILED: default: - printf ("Checking parent status failed: %d\n", GetLastError ()); + printf ("Checking parent status failed: %lu\n", GetLastError ()); exit (1); } } @@ -250,16 +258,6 @@ fchown (int fd, unsigned uid, unsigned gid) return 0; } -/* Place a wrapper around the MSVC version of ctime. It returns NULL - on network directories, so we handle that case here. - (Ulrich Leodolter, 1/11/95). */ -char * -sys_ctime (const time_t *t) -{ - char *str = (char *) ctime (t); - return (str ? str : "Sun Jan 01 00:00:00 1970"); -} - FILE * sys_fopen (const char * path, const char * mode) { diff --git a/lib-src/ntlib.h b/lib-src/ntlib.h index b49da79f328..4849dccb032 100644 --- a/lib-src/ntlib.h +++ b/lib-src/ntlib.h @@ -34,15 +34,12 @@ char *getwd (char *dir); int getppid (void); char * getlogin (void); char * cuserid (char * s); -unsigned getuid (void); -unsigned geteuid (void); unsigned getegid (void); unsigned getgid (void); int setuid (unsigned uid); int setregid (unsigned rgid, unsigned gid); char * getpass (const char * prompt); int fchown (int fd, unsigned uid, unsigned gid); -int mkostemp (char * template, int flags); /* redirect or undo interceptions created by config.h */ #undef access diff --git a/lib-src/pop.c b/lib-src/pop.c index 6e3b6a9a773..99424c584c2 100644 --- a/lib-src/pop.c +++ b/lib-src/pop.c @@ -28,7 +28,17 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <sys/types.h> #ifdef WINDOWSNT #include "ntlib.h" -#include <winsock.h> +#undef _WIN32_WINNT +#define _WIN32_WINNT 0x0501 /* for getaddrinfo stuff */ +#include <winsock2.h> +#include <ws2tcpip.h> +#undef getaddrinfo +#define getaddrinfo sys_getaddrinfo +#undef freeaddrinfo +#define freeaddrinfo sys_freeaddrinfo +int sys_getaddrinfo (const char * node, const char * service, + const struct addrinfo * hints, struct addrinfo ** res); +void sys_freeaddrinfo (struct addrinfo * ai); #undef SOCKET_ERROR #define RECV(s,buf,len,flags) recv (s,buf,len,flags) #define SEND(s,buf,len,flags) send (s,buf,len,flags) @@ -53,10 +63,12 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ extern struct servent *hes_getservbyname (/* char *, char * */); #endif +#include <alloca.h> #include <pwd.h> #include <netdb.h> #include <errno.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <unistd.h> @@ -80,6 +92,7 @@ extern struct servent *hes_getservbyname (/* char *, char * */); # endif #endif /* KERBEROS */ +#include <c-ctype.h> #include <min-max.h> #ifdef KERBEROS @@ -92,12 +105,6 @@ extern char *krb_realmofhost (/* char * */); #endif /* ! KERBEROS5 */ #endif /* KERBEROS */ -#ifndef WINDOWSNT -#ifndef HAVE_H_ERRNO -extern int h_errno; -#endif -#endif - static int socket_connection (char *, int); static int pop_getline (popserver, char **); static int sendline (popserver, const char *); @@ -714,7 +721,8 @@ pop_multi_next (popserver server, char **line) return (-1); } - if ((ret = pop_getline (server, &fromserver)) < 0) + ret = pop_getline (server, &fromserver); + if (ret < 0) { return (-1); } @@ -962,13 +970,9 @@ static int have_winsock = 0; static int socket_connection (char *host, int flags) { -#ifdef HAVE_GETADDRINFO struct addrinfo *res, *it; struct addrinfo hints; int ret; -#else /* !HAVE_GETADDRINFO */ - struct hostent *hostent; -#endif struct servent *servent; struct sockaddr_in addr; char found_port = 0; @@ -1055,7 +1059,6 @@ socket_connection (char *host, int flags) } -#ifdef HAVE_GETADDRINFO memset (&hints, 0, sizeof (hints)); hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_CANONNAME; @@ -1087,34 +1090,6 @@ socket_connection (char *host, int flags) } freeaddrinfo (res); -#else /* !HAVE_GETADDRINFO */ - do - { - hostent = gethostbyname (host); - try_count++; - if ((! hostent) && ((h_errno != TRY_AGAIN) || (try_count == 5))) - { - strcpy (pop_error, "Could not determine POP server's address"); - return (-1); - } - } while (! hostent); - - while (*hostent->h_addr_list) - { - memcpy (&addr.sin_addr, *hostent->h_addr_list, hostent->h_length); - if (! connect (sock, (struct sockaddr *) &addr, sizeof (addr))) - break; - hostent->h_addr_list++; - } - connect_ok = *hostent->h_addr_list != NULL; - if (! connect_ok) - { - realhost = alloca (strlen (hostent->h_name) + 1); - strcpy (realhost, hostent->h_name); - } - -#endif /* !HAVE_GETADDRINFO */ - #define CONNECT_ERROR "Could not connect to POP server: " if (! connect_ok) @@ -1131,7 +1106,8 @@ socket_connection (char *host, int flags) if (! (flags & POP_NO_KERBEROS)) { #ifdef KERBEROS5 - if ((rem = krb5_init_context (&kcontext))) + rem = krb5_init_context (&kcontext); + if (rem) { krb5error: if (auth_context) @@ -1144,29 +1120,29 @@ socket_connection (char *host, int flags) return (-1); } - if ((rem = krb5_auth_con_init (kcontext, &auth_context))) + rem = krb5_auth_con_init (kcontext, &auth_context); + if (rem) goto krb5error; - if (rem = krb5_cc_default (kcontext, &ccdef)) + rem = krb5_cc_default (kcontext, &ccdef); + if (rem) goto krb5error; - if (rem = krb5_cc_get_principal (kcontext, ccdef, &client)) + rem = krb5_cc_get_principal (kcontext, ccdef, &client); + if (rem) goto krb5error; for (cp = realhost; *cp; cp++) - { - if (isupper (*cp)) - { - *cp = tolower (*cp); - } - } + *cp = c_tolower (*cp); - if (rem = krb5_sname_to_principal (kcontext, realhost, - POP_SERVICE, FALSE, &server)) + rem = krb5_sname_to_principal (kcontext, realhost, + POP_SERVICE, FALSE, &server); + if (rem) goto krb5error; rem = krb5_sendauth (kcontext, &auth_context, - (krb5_pointer) &sock, "KPOPV1.0", client, server, + (krb5_pointer) &sock, (char *) "KPOPV1.0", + client, server, AP_OPTS_MUTUAL_REQUIRED, 0, /* no checksum */ 0, /* no creds, use ccache instead */ @@ -1581,4 +1557,143 @@ find_crlf (char *in_string, int len) return (0); } +#ifdef WINDOWSNT +/* The following 2 functions are only available since XP, so we load + them dynamically and provide fallbacks. */ + +int (WINAPI *pfn_getaddrinfo) (const char *, const char *, + const struct addrinfo *, struct addrinfo **); +void (WINAPI *pfn_freeaddrinfo) (struct addrinfo *); + +static int +load_ws2 (void) +{ + static int ws2_loaded = 0; + + if (!ws2_loaded) + { + HANDLE ws2_lib = LoadLibrary ("Ws2_32.dll"); + + if (ws2_lib != NULL) + { + ws2_loaded = 1; + pfn_getaddrinfo = (void *) GetProcAddress (ws2_lib, "getaddrinfo"); + pfn_freeaddrinfo = (void *) GetProcAddress (ws2_lib, "freeaddrinfo"); + /* Paranoia: these two functions should go together, so if + one is absent, we cannot use the other. */ + if (pfn_getaddrinfo == NULL) + pfn_freeaddrinfo = NULL; + else if (pfn_freeaddrinfo == NULL) + pfn_getaddrinfo = NULL; + } + } + if (!ws2_loaded) + { + errno = ENETDOWN; + return -1; + } + return 0; +} + + +int +sys_getaddrinfo (const char *node, const char *service, + const struct addrinfo *hints, struct addrinfo **res) +{ + int rc; + + if (load_ws2 () != 0) + { + errno = ENETDOWN; + return WSANO_RECOVERY; + } + + if (pfn_getaddrinfo) + rc = pfn_getaddrinfo (node, service, hints, res); + else + { + int port = 0; + struct hostent *host_info; + struct gai_storage { + struct addrinfo addrinfo; + struct sockaddr_in sockaddr_in; + } *gai_storage; + + /* We don't support any flags besides AI_CANONNAME. */ + if (hints && (hints->ai_flags & ~(AI_CANONNAME)) != 0) + return WSAEINVAL; + /* NODE cannot be NULL, since pop.c has fallbacks for that. */ + if (!node) + return WSAHOST_NOT_FOUND; + + if (service) + { + const char *protocol = + (hints && hints->ai_socktype == SOCK_DGRAM) ? "udp" : "tcp"; + struct servent *srv = getservbyname (service, protocol); + + if (srv) + port = srv->s_port; + else + return WSAHOST_NOT_FOUND; + } + + gai_storage = calloc (1, sizeof *gai_storage); + gai_storage->sockaddr_in.sin_port = port; + host_info = gethostbyname (node); + if (host_info) + { + memcpy (&gai_storage->sockaddr_in.sin_addr, + host_info->h_addr, host_info->h_length); + gai_storage->sockaddr_in.sin_family = host_info->h_addrtype; + } + else + { + free (gai_storage); + return WSAHOST_NOT_FOUND; + } + + gai_storage->addrinfo.ai_addr = + (struct sockaddr *)&gai_storage->sockaddr_in; + gai_storage->addrinfo.ai_addrlen = sizeof (gai_storage->sockaddr_in); + if (hints && (hints->ai_flags & AI_CANONNAME) != 0) + { + gai_storage->addrinfo.ai_canonname = strdup (host_info->h_name); + if (!gai_storage->addrinfo.ai_canonname) + { + free (gai_storage); + return WSA_NOT_ENOUGH_MEMORY; + } + } + gai_storage->addrinfo.ai_protocol = (hints) ? hints->ai_protocol : 0; + gai_storage->addrinfo.ai_socktype = (hints) ? hints->ai_socktype : 0; + gai_storage->addrinfo.ai_family = gai_storage->sockaddr_in.sin_family; + gai_storage->addrinfo.ai_next = NULL; + + *res = &gai_storage->addrinfo; + rc = 0; + } + + return rc; +} + +void +sys_freeaddrinfo (struct addrinfo *ai) +{ + if (load_ws2 () != 0) + { + errno = ENETDOWN; + return; + } + + if (pfn_freeaddrinfo) + pfn_freeaddrinfo (ai); + else + { + if (ai->ai_canonname) + free (ai->ai_canonname); + free (ai); + } +} +#endif /* WINDOWSNT */ #endif /* MAIL_USE_POP */ diff --git a/lib-src/profile.c b/lib-src/profile.c index 0e603776049..cfee5b8608f 100644 --- a/lib-src/profile.c +++ b/lib-src/profile.c @@ -35,6 +35,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <inttypes.h> #include <stdio.h> +#include <stdlib.h> #include <intprops.h> #include <systime.h> @@ -84,13 +85,13 @@ main (void) puts (get_time ()); break; case 'q': - exit (EXIT_SUCCESS); + return EXIT_SUCCESS; } /* Anything remaining on the line is ignored. */ while (c != '\n' && c != EOF) c = getchar (); } - exit (EXIT_FAILURE); + return EXIT_FAILURE; } diff --git a/lib-src/update-game-score.c b/lib-src/update-game-score.c index 7675e9bdd4c..7e1b332bdcd 100644 --- a/lib-src/update-game-score.c +++ b/lib-src/update-game-score.c @@ -37,7 +37,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <errno.h> #include <inttypes.h> #include <limits.h> -#include <stdbool.h> #include <string.h> #include <stdlib.h> #include <stdio.h> |