This commit was generated by cvs2svn to track changes on a CVS vendor
[external/binutils.git] / gdb / gdbserver / utils.c
1 /* General utility routines for the remote server for GDB.
2    Copyright (C) 1986, 1989, 1993 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20 #include "server.h"
21 #include <stdio.h>
22
23 /* Generally useful subroutines used throughout the program.  */
24
25 /* Print the system error message for errno, and also mention STRING
26    as the file name for which the error was encountered.
27    Then return to command level.  */
28
29 void
30 perror_with_name (string)
31      char *string;
32 {
33   extern int sys_nerr;
34   extern char *sys_errlist[];
35   extern int errno;
36   char *err;
37   char *combined;
38
39   if (errno < sys_nerr)
40     err = sys_errlist[errno];
41   else
42     err = "unknown error";
43
44   combined = (char *) alloca (strlen (err) + strlen (string) + 3);
45   strcpy (combined, string);
46   strcat (combined, ": ");
47   strcat (combined, err);
48
49   error ("%s.", combined);
50 }
51
52 /* Print an error message and return to command level.
53    STRING is the error message, used as a fprintf string,
54    and ARG is passed as an argument to it.  */
55
56 NORETURN void
57 error (string, arg1, arg2, arg3)
58      char *string;
59      int arg1, arg2, arg3;
60 {
61   extern jmp_buf toplevel;
62
63   fflush (stdout);
64   fprintf (stderr, string, arg1, arg2, arg3);
65   fprintf (stderr, "\n");
66   longjmp(toplevel, 1);
67 }
68
69 /* Print an error message and exit reporting failure.
70    This is for a error that we cannot continue from.
71    STRING and ARG are passed to fprintf.  */
72
73 void
74 fatal (string, arg)
75      char *string;
76      int arg;
77 {
78   fprintf (stderr, "gdb: ");
79   fprintf (stderr, string, arg);
80   fprintf (stderr, "\n");
81   exit (1);
82 }