Port to C89.
[bpt/emacs.git] / lib-src / emacsclient.c
index 8d60d79..74ccfa2 100644 (file)
@@ -1,6 +1,6 @@
 /* Client process that communicates with GNU Emacs acting as server.
 
-Copyright (C) 1986-1987, 1994, 1999-2012 Free Software Foundation, Inc.
+Copyright (C) 1986-1987, 1994, 1999-2013 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -88,10 +88,7 @@ char *w32_getenv (char *);
 
 
 \f
-char *getenv (const char *), *getwd (char *);
-#ifdef HAVE_GETCWD
-char *(getcwd) (char *, size_t);
-#endif
+char *getenv (const char *);
 
 #ifndef VERSION
 #define VERSION "unspecified"
@@ -223,7 +220,7 @@ get_current_dir_name (void)
   char *buf;
   const char *pwd;
   struct stat dotstat, pwdstat;
-  /* If PWD is accurate, use it instead of calling getwd.  PWD is
+  /* 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
@@ -240,7 +237,6 @@ get_current_dir_name (void)
       buf = (char *) xmalloc (strlen (pwd) + 1);
       strcpy (buf, pwd);
     }
-#ifdef HAVE_GETCWD
   else
     {
       size_t buf_size = 1024;
@@ -267,20 +263,6 @@ get_current_dir_name (void)
            }
         }
     }
-#else
-  else
-    {
-      /* We need MAXPATHLEN here.  */
-      buf = (char *) xmalloc (MAXPATHLEN + 1);
-      if (getwd (buf) == NULL)
-        {
-          int tmp_errno = errno;
-          free (buf);
-          errno = tmp_errno;
-          return NULL;
-        }
-    }
-#endif
   return buf;
 }
 #endif
@@ -648,7 +630,7 @@ print_help_and_exit (void)
      Please try to preserve them; otherwise the output is very hard to read
      when using emacsclientw.  */
   message (FALSE,
-          "Usage: %s [OPTIONS] FILE...\n\
+          "Usage: %s [OPTIONS] FILE...\n%s%s%s", progname, "\
 Tell the Emacs server to visit the specified files.\n\
 Every FILE can be either just a FILENAME or [+LINE[:COLUMN]] FILENAME.\n\
 \n\
@@ -658,6 +640,7 @@ The following OPTIONS are accepted:\n\
 -nw, -t, --tty                 Open a new Emacs frame on the current terminal\n\
 -c, --create-frame     Create a new frame instead of trying to\n\
                        use the current Emacs frame\n\
+", "\
 -F ALIST, --frame-parameters=ALIST\n\
                        Set the parameters of a new frame\n\
 -e, --eval             Evaluate the FILE arguments as ELisp expressions\n\
@@ -665,6 +648,7 @@ The following OPTIONS are accepted:\n\
 -q, --quiet            Don't display messages on success\n\
 -d DISPLAY, --display=DISPLAY\n\
                        Visit the file in the given display\n\
+", "\
 --parent-id=ID          Open in parent window ID, via XEmbed\n"
 #ifndef NO_SOCKETS_IN_FILE_SYSTEM
 "-s SOCKET, --socket-name=SOCKET\n\
@@ -679,7 +663,7 @@ The following OPTIONS are accepted:\n\
                        mode and try connecting again\n"
 #endif /* not WINDOWSNT */
 "\n\
-Report bugs with M-x report-emacs-bug.\n", progname);
+Report bugs with M-x report-emacs-bug.\n");
   exit (EXIT_SUCCESS);
 }
 
@@ -1138,7 +1122,7 @@ handle_sigcont (int signalnum)
   else
     {
       /* We are in the background; cancel the continue. */
-      kill (getpid (), SIGSTOP);
+      raise (SIGSTOP);
     }
 
   signal (signalnum, handle_sigcont);
@@ -1165,7 +1149,7 @@ handle_sigtstp (int signalnum)
   sigprocmask (SIG_BLOCK, NULL, &set);
   sigdelset (&set, signalnum);
   signal (signalnum, SIG_DFL);
-  kill (getpid (), signalnum);
+  raise (signalnum);
   sigprocmask (SIG_SETMASK, &set, NULL); /* Let's the above signal through. */
   signal (signalnum, handle_sigtstp);
 
@@ -1527,7 +1511,10 @@ start_daemon_and_retry_set_socket (void)
     {
       char emacs[] = "emacs";
       char daemon_option[] = "--daemon";
-      char *d_argv[] = {emacs, daemon_option, 0 };
+      char *d_argv[3];
+      d_argv[0] = emacs;
+      d_argv[1] = daemon_option;
+      d_argv[2] = 0;
       if (socket_name != NULL)
        {
          /* Pass  --daemon=socket_name as argument.  */
@@ -1592,7 +1579,6 @@ main (int argc, char **argv)
   cwd = get_current_dir_name ();
   if (cwd == 0)
     {
-      /* getwd puts message in STRING if it fails.  */
       message (TRUE, "%s: %s\n", progname,
               "Cannot get current working directory");
       fail ();
@@ -1743,7 +1729,8 @@ main (int argc, char **argv)
       needlf = 2;
     }
   fflush (stdout);
-  fsync (1);
+  while (fdatasync (1) != 0 && errno == EINTR)
+    continue;
 
   /* Now, wait for an answer and print any messages.  */
   while (exit_status == EXIT_SUCCESS)
@@ -1844,7 +1831,8 @@ main (int argc, char **argv)
   if (needlf)
     printf ("\n");
   fflush (stdout);
-  fsync (1);
+  while (fdatasync (1) != 0 && errno == EINTR)
+    continue;
 
   if (rl < 0)
     exit_status = EXIT_FAILURE;