diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2018-11-19 11:07:08 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2018-11-19 11:38:20 -0800 |
commit | b944e88663c0c3086976188e1b3da6fc7f21261e (patch) | |
tree | b2f10e0b0121589d08d7a78cd95232d2876e7531 /lib-src | |
parent | 95ea5c257cde5e692ff3adc2b1f75c9f583b91a6 (diff) | |
download | emacs-b944e88663c0c3086976188e1b3da6fc7f21261e.tar.gz |
emacsclient.c: use C99 better
* lib-src/emacsclient.c (get_current_dir_name)
(send_to_emacs, set_tcp_socket, set_local_socket, main):
Take advantage of C99 stmt before decl.
Diffstat (limited to 'lib-src')
-rw-r--r-- | lib-src/emacsclient.c | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 7e7b2a3b0c5..153f65fc916 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -228,12 +228,12 @@ char * get_current_dir_name (void) { char *buf; - const char *pwd; struct stat dotstat, pwdstat; /* If PWD is accurate, use it instead of calling getcwd. PWD is sometimes a nicer name, and using it may avoid a fatal error if a parent directory is searchable but not readable. */ - if ((pwd = egetenv ("PWD")) != 0 + char const *pwd = egetenv ("PWD"); + if (pwd && (IS_DIRECTORY_SEP (*pwd) || (*pwd && IS_DEVICE_SEP (pwd[1]))) && stat (pwd, &pwdstat) == 0 && stat (".", &dotstat) == 0 @@ -782,21 +782,15 @@ send_to_emacs (HSOCKET s, const char *data) /* Fill pointer for the send buffer. */ static int sblen; - size_t dlen; - - if (!data) - return; - - dlen = strlen (data); - while (*data) + for (ptrdiff_t dlen = strlen (data); dlen != 0; ) { - size_t part = min (dlen, SEND_BUFFER_SIZE - sblen); + int part = min (dlen, SEND_BUFFER_SIZE - sblen); memcpy (&send_buffer[sblen], data, part); data += part; sblen += part; if (sblen == SEND_BUFFER_SIZE - || (sblen > 0 && send_buffer[sblen-1] == '\n')) + || (0 < sblen && send_buffer[sblen - 1] == '\n')) { int sent = send (s, send_buffer, sblen, 0); if (sent < 0) @@ -1015,7 +1009,6 @@ get_server_config (const char *config_file, struct sockaddr_in *server, static HSOCKET set_tcp_socket (const char *local_server_file) { - HSOCKET s; struct sockaddr_in server; struct linger l_arg = {1, 1}; char auth_string[AUTH_KEY_LENGTH + 1]; @@ -1028,7 +1021,8 @@ set_tcp_socket (const char *local_server_file) progname, inet_ntoa (server.sin_addr)); /* Open up an AF_INET socket. */ - if ((s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) + HSOCKET s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); + if (s < 0) { /* Since we have an alternate to try out, this is not an error yet; popping out a modal dialog at this stage would make -a @@ -1225,11 +1219,11 @@ init_signals (void) static HSOCKET set_local_socket (const char *local_socket_name) { - HSOCKET s; struct sockaddr_un server; /* Open up an AF_UNIX socket in this person's home directory. */ - if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) + HSOCKET s = socket (AF_UNIX, SOCK_STREAM, 0); + if (s < 0) { message (true, "%s: socket: %s\n", progname, strerror (errno)); return INVALID_SOCKET; @@ -1712,11 +1706,10 @@ main (int argc, char **argv) /* Send over our environment and current directory. */ if (create_frame) { - int i; - for (i = 0; environ[i]; i++) + for (char *const *e = environ; *e; e++) { send_to_emacs (emacs_socket, "-env "); - quote_argument (emacs_socket, environ[i]); + quote_argument (emacs_socket, *e); send_to_emacs (emacs_socket, " "); } } @@ -1781,8 +1774,7 @@ main (int argc, char **argv) if (optind < argc) { - int i; - for (i = optind; i < argc; i++) + for (int i = optind; i < argc; i++) { if (eval) @@ -1794,11 +1786,15 @@ main (int argc, char **argv) continue; } - if (*argv[i] == '+') + char *p = argv[i]; + if (*p == '+') { - char *p = argv[i] + 1; - while (isdigit ((unsigned char) *p) || *p == ':') p++; - if (*p == 0) + unsigned char c; + do + c = *++p; + while (isdigit (c) || c == ':'); + + if (c == 0) { send_to_emacs (emacs_socket, "-position "); quote_argument (emacs_socket, argv[i]); @@ -1860,7 +1856,6 @@ main (int argc, char **argv) /* Now, wait for an answer and print any messages. */ while (exit_status == EXIT_SUCCESS) { - char *p, *end_p; do { errno = 0; @@ -1876,7 +1871,8 @@ main (int argc, char **argv) string[rl] = '\0'; /* Loop over all NL-terminated messages. */ - for (end_p = p = string; end_p != NULL && *end_p != '\0'; p = end_p) + char *p = string; + for (char *end_p = p; end_p && *end_p != '\0'; p = end_p) { end_p = strchr (p, '\n'); if (end_p != NULL) |