* configure.ac: Switch license to GPLv3.
[deliverable/binutils-gdb.git] / gdb / gdbserver / utils.c
CommitLineData
c906108c 1/* General utility routines for the remote server for GDB.
6aba47ca
DJ
2 Copyright (C) 1986, 1989, 1993, 1995, 1996, 1997, 1999, 2000, 2002, 2003,
3 2007 Free Software Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
c906108c 11
c5aa993b
JM
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
c906108c 16
c5aa993b
JM
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
6f0f660e
EZ
19 Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
c906108c
SS
21
22#include "server.h"
23#include <stdio.h>
24#include <string.h>
68070c10
PA
25#include <stdlib.h>
26#if HAVE_ERRNO_H
27#include <errno.h>
28#endif
29#if HAVE_MALLOC_H
30#include <malloc.h>
31#endif
c906108c
SS
32
33/* Generally useful subroutines used throughout the program. */
34
35/* Print the system error message for errno, and also mention STRING
36 as the file name for which the error was encountered.
37 Then return to command level. */
38
39void
fba45db2 40perror_with_name (char *string)
c906108c 41{
5c44784c 42 const char *err;
c906108c
SS
43 char *combined;
44
43d5792c
DJ
45 err = strerror (errno);
46 if (err == NULL)
c906108c
SS
47 err = "unknown error";
48
49 combined = (char *) alloca (strlen (err) + strlen (string) + 3);
50 strcpy (combined, string);
51 strcat (combined, ": ");
52 strcat (combined, err);
53
54 error ("%s.", combined);
55}
56
57/* Print an error message and return to command level.
58 STRING is the error message, used as a fprintf string,
59 and ARG is passed as an argument to it. */
60
0729219d 61void
c5aa993b 62error (const char *string,...)
c906108c
SS
63{
64 extern jmp_buf toplevel;
65 va_list args;
c906108c 66 va_start (args, string);
c906108c 67 fflush (stdout);
c906108c 68 vfprintf (stderr, string, args);
c906108c 69 fprintf (stderr, "\n");
c5aa993b 70 longjmp (toplevel, 1);
c906108c
SS
71}
72
73/* Print an error message and exit reporting failure.
74 This is for a error that we cannot continue from.
75 STRING and ARG are passed to fprintf. */
76
77/* VARARGS */
0729219d 78void
0a30fbc4 79fatal (const char *string,...)
c906108c
SS
80{
81 va_list args;
c906108c 82 va_start (args, string);
c906108c
SS
83 fprintf (stderr, "gdb: ");
84 vfprintf (stderr, string, args);
85 fprintf (stderr, "\n");
86 va_end (args);
87 exit (1);
88}
0a30fbc4
DJ
89
90/* VARARGS */
91void
92warning (const char *string,...)
93{
94 va_list args;
95 va_start (args, string);
96 fprintf (stderr, "gdb: ");
97 vfprintf (stderr, string, args);
98 fprintf (stderr, "\n");
99 va_end (args);
100}
This page took 0.516437 seconds and 4 git commands to generate.