/* Client process that communicates with GNU Emacs acting as server.
- Copyright (C) 1986, 1987, 1994 Free Software Foundation, Inc.
+ Copyright (C) 1986, 1987, 1994, 1999 Free Software Foundation, Inc.
This file is part of GNU Emacs.
#define NO_SHORTNAMES
#include <../src/config.h>
-#undef read
-#undef write
-#undef open
-#undef close
#undef signal
#include <stdio.h>
#include <getopt.h>
-#ifdef STDC_HEADERS
-#include <stdlib.h>
-#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
break;
case 'V':
- fprintf (stderr, "Version %s\n", VERSION);
+ fprintf (stderr, "emacsclient %s\n", VERSION);
exit (1);
break;
"Usage: %s [-n] [--no-wait] [+LINENUMBER] FILENAME\n",
progname);
fprintf (stderr,
- "Report bugs to bug-gnu-emacs@prep.ai.mit.edu.\n");
+ "Or %s --version\n",
+ progname);
+ fprintf (stderr,
+ "Report bugs to bug-gnu-emacs@gnu.org.\n");
exit (1);
}
return copy;
}
-#ifdef C_ALLOCA
/* Like malloc but get fatal error if memory is exhausted. */
-char *
+long *
xmalloc (size)
unsigned int size;
{
- char *result = (char *) malloc (size);
+ long *result = (long *) malloc (size);
if (result == NULL)
{
perror ("malloc");
}
return result;
}
-#endif /* C_ALLOCA */
\f
#if !defined (HAVE_SOCKETS) && !defined (HAVE_SYSVIPC)
int argc;
char **argv;
{
- char system_name[32];
+ char *system_name;
+ int system_name_length;
int s, i;
FILE *out, *in;
struct sockaddr_un server;
exit (1);
}
server.sun_family = AF_UNIX;
+
+ {
+ system_name_length = 32;
+
+ while (1)
+ {
+ system_name = (char *) xmalloc (system_name_length + 1);
+
+ /* system_name must be null-terminated string. */
+ system_name[system_name_length] = '\0';
+
+ if (gethostname (system_name, system_name_length) == 0)
+ break;
+
+ free (system_name);
+ system_name_length *= 2;
+ }
+ }
+
#ifndef SERVER_HOME_DIR
{
struct stat statbfr;
- gethostname (system_name, sizeof (system_name));
- /* system_name must be null-terminated string */
- system_name[sizeof (system_name) - 1] = '\0';
sprintf (server.sun_path, "/tmp/esrv%d-%s", geteuid (), system_name);
if (stat (server.sun_path, &statbfr) == -1)
}
strcpy (server.sun_path, homedir);
strcat (server.sun_path, "/.emacs-server-");
- gethostname (system_name, sizeof (system_name));
strcat (server.sun_path, system_name);
#endif
char *p = argv[i] + 1;
while (*p >= '0' && *p <= '9') p++;
if (*p != 0)
- fprintf (out, "%s/", cwd);
+ fprintf (out, "%s/", quote_file_name (cwd));
}
else if (*argv[i] != '/')
- fprintf (out, "%s/", cwd);
+ fprintf (out, "%s/", quote_file_name (cwd));
fprintf (out, "%s ", quote_file_name (argv[i]));
}
modified_arg = quote_file_name (modified_arg);
if (need_cwd)
- used += strlen (cwd);
+ /* Overestimate in case we have to quote something in CWD. */
+ used += 2 * strlen (cwd);
used += strlen (modified_arg) + 1;
while (used + 2 > size_allocated)
{
}
if (need_cwd)
- strcat (msgp->mtext, cwd);
+ strcat (msgp->mtext, quote_file_name (cwd));
strcat (msgp->mtext, modified_arg);
strcat (msgp->mtext, " ");