aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src/emacsclient.c
diff options
context:
space:
mode:
authorPaul Eggert2011-02-25 21:54:36 -0800
committerPaul Eggert2011-02-25 21:54:36 -0800
commitae3f8fbfc330c91272411720263bd9eb0c5bb82a (patch)
treeb5b475176540b655a3478f157c8d445f0f63a7a8 /lib-src/emacsclient.c
parent61e9662ef52e9b4a257fc9dd3c3812af2657f70a (diff)
parent9e1b7fe6be807a6081988aa2834b9489110d9ded (diff)
downloademacs-ae3f8fbfc330c91272411720263bd9eb0c5bb82a.tar.gz
emacs-ae3f8fbfc330c91272411720263bd9eb0c5bb82a.zip
Merge: lib-src changes mostly to avoid GCC warnings
Diffstat (limited to 'lib-src/emacsclient.c')
-rw-r--r--lib-src/emacsclient.c92
1 files changed, 44 insertions, 48 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index 8d5f0482637..251f35873e3 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -112,6 +112,13 @@ char *(getcwd) (char *, size_t);
112/* Additional space when allocating buffers for filenames, etc. */ 112/* Additional space when allocating buffers for filenames, etc. */
113#define EXTRA_SPACE 100 113#define EXTRA_SPACE 100
114 114
115/* Use this to suppress gcc's `...may be used before initialized' warnings. */
116#ifdef lint
117# define IF_LINT(Code) Code
118#else
119# define IF_LINT(Code) /* empty */
120#endif
121
115 122
116/* Name used to invoke this program. */ 123/* Name used to invoke this program. */
117const char *progname; 124const char *progname;
@@ -190,20 +197,6 @@ xmalloc (unsigned int size)
190 return result; 197 return result;
191} 198}
192 199
193/* Like strdup but get a fatal error if memory is exhausted. */
194
195static char *
196xstrdup (const char *s)
197{
198 char *result = strdup (s);
199 if (result == NULL)
200 {
201 perror ("strdup");
202 exit (EXIT_FAILURE);
203 }
204 return result;
205}
206
207/* From sysdep.c */ 200/* From sysdep.c */
208#if !defined (HAVE_GET_CURRENT_DIR_NAME) || defined (BROKEN_GET_CURRENT_DIR_NAME) 201#if !defined (HAVE_GET_CURRENT_DIR_NAME) || defined (BROKEN_GET_CURRENT_DIR_NAME)
209 202
@@ -233,7 +226,7 @@ char*
233get_current_dir_name (void) 226get_current_dir_name (void)
234{ 227{
235 char *buf; 228 char *buf;
236 char *pwd; 229 const char *pwd;
237 struct stat dotstat, pwdstat; 230 struct stat dotstat, pwdstat;
238 /* If PWD is accurate, use it instead of calling getwd. PWD is 231 /* If PWD is accurate, use it instead of calling getwd. PWD is
239 sometimes a nicer name, and using it may avoid a fatal error if a 232 sometimes a nicer name, and using it may avoid a fatal error if a
@@ -353,7 +346,7 @@ w32_getenv (char *envvar)
353 { 346 {
354 /* "w32console" is what Emacs on Windows uses for tty-type under -nw. */ 347 /* "w32console" is what Emacs on Windows uses for tty-type under -nw. */
355 if (strcmp (envvar, "TERM") == 0) 348 if (strcmp (envvar, "TERM") == 0)
356 return xstrdup ("w32console"); 349 return "w32console";
357 /* Found neither in the environment nor in the registry. */ 350 /* Found neither in the environment nor in the registry. */
358 return NULL; 351 return NULL;
359 } 352 }
@@ -474,13 +467,13 @@ ttyname (int fd)
474/* Display a normal or error message. 467/* Display a normal or error message.
475 On Windows, use a message box if compiled as a Windows app. */ 468 On Windows, use a message box if compiled as a Windows app. */
476static void 469static void
477message (int is_error, const char *message, ...) 470message (int is_error, const char *format, ...)
478{ 471{
479 char msg[2048]; 472 char msg[2048];
480 va_list args; 473 va_list args;
481 474
482 va_start (args, message); 475 va_start (args, format);
483 vsprintf (msg, message, args); 476 vsprintf (msg, format, args);
484 va_end (args); 477 va_end (args);
485 478
486#ifdef WINDOWSNT 479#ifdef WINDOWSNT
@@ -918,7 +911,7 @@ get_server_config (struct sockaddr_in *server, char *authentication)
918 config = fopen (server_file, "rb"); 911 config = fopen (server_file, "rb");
919 else 912 else
920 { 913 {
921 char *home = egetenv ("HOME"); 914 const char *home = egetenv ("HOME");
922 915
923 if (home) 916 if (home)
924 { 917 {
@@ -1025,10 +1018,10 @@ strprefix (const char *prefix, const char *string)
1025 is zero, or return 0 if NOABORT is non-zero. */ 1018 is zero, or return 0 if NOABORT is non-zero. */
1026 1019
1027static int 1020static int
1028find_tty (char **tty_type, char **tty_name, int noabort) 1021find_tty (const char **tty_type, const char **tty_name, int noabort)
1029{ 1022{
1030 char *type = egetenv ("TERM"); 1023 const char *type = egetenv ("TERM");
1031 char *name = ttyname (fileno (stdout)); 1024 const char *name = ttyname (fileno (stdout));
1032 1025
1033 if (!name) 1026 if (!name)
1034 { 1027 {
@@ -1080,11 +1073,11 @@ find_tty (char **tty_type, char **tty_name, int noabort)
1080 0 - success: none of the above */ 1073 0 - success: none of the above */
1081 1074
1082static int 1075static int
1083socket_status (char *socket_name) 1076socket_status (char *name)
1084{ 1077{
1085 struct stat statbfr; 1078 struct stat statbfr;
1086 1079
1087 if (stat (socket_name, &statbfr) == -1) 1080 if (stat (name, &statbfr) == -1)
1088 return 2; 1081 return 2;
1089 1082
1090 if (statbfr.st_uid != geteuid ()) 1083 if (statbfr.st_uid != geteuid ())
@@ -1205,7 +1198,7 @@ set_local_socket (void)
1205 int default_sock = !socket_name; 1198 int default_sock = !socket_name;
1206 int saved_errno = 0; 1199 int saved_errno = 0;
1207 const char *server_name = "server"; 1200 const char *server_name = "server";
1208 const char *tmpdir; 1201 const char *tmpdir IF_LINT ( = NULL);
1209 1202
1210 if (socket_name && !strchr (socket_name, '/') 1203 if (socket_name && !strchr (socket_name, '/')
1211 && !strchr (socket_name, '\\')) 1204 && !strchr (socket_name, '\\'))
@@ -1260,10 +1253,10 @@ set_local_socket (void)
1260 associated with the name. This is reminiscent of the logic 1253 associated with the name. This is reminiscent of the logic
1261 that init_editfns uses to set the global Vuser_full_name. */ 1254 that init_editfns uses to set the global Vuser_full_name. */
1262 1255
1263 char *user_name = (char *) egetenv ("LOGNAME"); 1256 const char *user_name = egetenv ("LOGNAME");
1264 1257
1265 if (!user_name) 1258 if (!user_name)
1266 user_name = (char *) egetenv ("USER"); 1259 user_name = egetenv ("USER");
1267 1260
1268 if (user_name) 1261 if (user_name)
1269 { 1262 {
@@ -1483,8 +1476,8 @@ start_daemon_and_retry_set_socket (void)
1483 else 1476 else
1484 { 1477 {
1485 char emacs[] = "emacs"; 1478 char emacs[] = "emacs";
1486 char daemon[] = "--daemon"; 1479 char daemon_option[] = "--daemon";
1487 char *d_argv[] = {emacs, daemon, 0 }; 1480 char *d_argv[] = {emacs, daemon_option, 0 };
1488 if (socket_name != NULL) 1481 if (socket_name != NULL)
1489 { 1482 {
1490 /* Pass --daemon=socket_name as argument. */ 1483 /* Pass --daemon=socket_name as argument. */
@@ -1504,10 +1497,12 @@ start_daemon_and_retry_set_socket (void)
1504int 1497int
1505main (int argc, char **argv) 1498main (int argc, char **argv)
1506{ 1499{
1507 int i, rl, needlf = 0; 1500 int rl, needlf = 0;
1508 char *cwd, *str; 1501 char *cwd, *str;
1509 char string[BUFSIZ+1]; 1502 char string[BUFSIZ+1];
1510 int null_socket_name, null_server_file, start_daemon_if_needed; 1503 int null_socket_name IF_LINT ( = 0);
1504 int null_server_file IF_LINT ( = 0);
1505 int start_daemon_if_needed;
1511 int exit_status = EXIT_SUCCESS; 1506 int exit_status = EXIT_SUCCESS;
1512 1507
1513 main_argv = argv; 1508 main_argv = argv;
@@ -1543,21 +1538,21 @@ main (int argc, char **argv)
1543 null_server_file = (server_file == NULL); 1538 null_server_file = (server_file == NULL);
1544 } 1539 }
1545 1540
1546 if ((emacs_socket = set_socket (alternate_editor 1541 emacs_socket = set_socket (alternate_editor || start_daemon_if_needed);
1547 || start_daemon_if_needed)) == INVALID_SOCKET) 1542 if (emacs_socket == INVALID_SOCKET)
1548 if (start_daemon_if_needed) 1543 {
1549 { 1544 if (! start_daemon_if_needed)
1550 /* Reset socket_name and server_file if they were NULL 1545 fail ();
1551 before the set_socket call. */ 1546
1552 if (null_socket_name) 1547 /* Reset socket_name and server_file if they were NULL
1553 socket_name = NULL; 1548 before the set_socket call. */
1554 if (null_server_file) 1549 if (null_socket_name)
1555 server_file = NULL; 1550 socket_name = NULL;
1556 1551 if (null_server_file)
1557 start_daemon_and_retry_set_socket (); 1552 server_file = NULL;
1558 } 1553
1559 else 1554 start_daemon_and_retry_set_socket ();
1560 fail (); 1555 }
1561 1556
1562 cwd = get_current_dir_name (); 1557 cwd = get_current_dir_name ();
1563 if (cwd == 0) 1558 if (cwd == 0)
@@ -1615,7 +1610,7 @@ main (int argc, char **argv)
1615 frame is available. */ 1610 frame is available. */
1616 if (tty || (current_frame && !eval)) 1611 if (tty || (current_frame && !eval))
1617 { 1612 {
1618 char *tty_type, *tty_name; 1613 const char *tty_type, *tty_name;
1619 1614
1620 if (find_tty (&tty_type, &tty_name, !tty)) 1615 if (find_tty (&tty_type, &tty_name, !tty))
1621 { 1616 {
@@ -1635,6 +1630,7 @@ main (int argc, char **argv)
1635 1630
1636 if ((argc - optind > 0)) 1631 if ((argc - optind > 0))
1637 { 1632 {
1633 int i;
1638 for (i = optind; i < argc; i++) 1634 for (i = optind; i < argc; i++)
1639 { 1635 {
1640 1636