~ubuntu-branches/ubuntu/lucid/cdrdao/lucid

« back to all changes in this revision

Viewing changes to scsilib/libschily/serrmsg.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Suffield
  • Date: 2004-06-24 22:33:16 UTC
  • Revision ID: james.westby@ubuntu.com-20040624223316-534onzugaeeyq61j
Tags: upstream-1.1.9
ImportĀ upstreamĀ versionĀ 1.1.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* @(#)serrmsg.c        1.3 03/06/15 Copyright 1985, 2000-2003 J. Schilling */
 
2
/*
 
3
 *      Routines for printing command errors
 
4
 *
 
5
 *      Copyright (c) 1985, 2000-2003 J. Schilling
 
6
 */
 
7
/*
 
8
 * This program is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; either version 2, or (at your option)
 
11
 * any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License along with
 
19
 * this program; see the file COPYING.  If not, write to the Free Software
 
20
 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
21
 */
 
22
 
 
23
#include <mconfig.h>
 
24
#include <unixstd.h>            /* include <sys/types.h> try to get size_t */
 
25
#include <stdio.h>              /* Try again for size_t */
 
26
#include <stdxlib.h>            /* Try again for size_t */
 
27
#include <standard.h>
 
28
#include <stdxlib.h>
 
29
#include <vadefs.h>
 
30
#include <strdefs.h>
 
31
#include <schily.h>
 
32
#ifndef HAVE_STRERROR
 
33
extern  char    *sys_errlist[];
 
34
extern  int     sys_nerr;
 
35
#endif
 
36
 
 
37
EXPORT  int     serrmsg         __PR((char *buf, size_t maxcnt, const char *, ...));
 
38
EXPORT  int     serrmsgno       __PR((int, char *buf, size_t maxcnt, const char *, ...));
 
39
LOCAL   int     _serrmsg        __PR((int, char *buf, size_t maxcnt, const char *, va_list));
 
40
 
 
41
/* VARARGS1 */
 
42
EXPORT int
 
43
#ifdef  PROTOTYPES
 
44
serrmsg(char *buf, size_t maxcnt, const char *msg, ...)
 
45
#else
 
46
serrmsg(buf, maxcnt, msg, va_alist)
 
47
        char    *buf;
 
48
        size_t  maxcnt;
 
49
        char    *msg;
 
50
        va_dcl
 
51
#endif
 
52
{
 
53
        va_list args;
 
54
        int     ret;
 
55
 
 
56
#ifdef  PROTOTYPES
 
57
        va_start(args, msg);
 
58
#else
 
59
        va_start(args);
 
60
#endif
 
61
        ret = _serrmsg(geterrno(), buf, maxcnt, msg, args);
 
62
        va_end(args);
 
63
        return (ret);
 
64
}
 
65
 
 
66
/* VARARGS2 */
 
67
#ifdef  PROTOTYPES
 
68
EXPORT int
 
69
serrmsgno(int err, char *buf, size_t maxcnt, const char *msg, ...)
 
70
#else
 
71
serrmsgno(err, buf, maxcnt, msg, va_alist)
 
72
        int     err;
 
73
        char    *buf;
 
74
        size_t  maxcnt;
 
75
        char    *msg;
 
76
        va_dcl
 
77
#endif
 
78
{
 
79
        va_list args;
 
80
        int     ret;
 
81
 
 
82
#ifdef  PROTOTYPES
 
83
        va_start(args, msg);
 
84
#else
 
85
        va_start(args);
 
86
#endif
 
87
        ret = _serrmsg(err, buf, maxcnt, msg, args);
 
88
        va_end(args);
 
89
        return (ret);
 
90
}
 
91
 
 
92
LOCAL int
 
93
_serrmsg(err, buf, maxcnt, msg, args)
 
94
        int             err;
 
95
        char            *buf;
 
96
        size_t          maxcnt;
 
97
        const char      *msg;
 
98
        va_list         args;
 
99
{
 
100
        int     ret;
 
101
        char    errbuf[20];
 
102
        char    *errnam;
 
103
        char    *prognam = get_progname();
 
104
 
 
105
        if (err < 0) {
 
106
                ret = js_snprintf(buf, maxcnt, "%s: %r", prognam, msg, args);
 
107
        } else {
 
108
                errnam = errmsgstr(err);
 
109
                if (errnam == NULL) {
 
110
                        (void) js_snprintf(errbuf, sizeof (errbuf),
 
111
                                                "Error %d", err);
 
112
                        errnam = errbuf;
 
113
                }
 
114
                ret = js_snprintf(buf, maxcnt,
 
115
                                "%s: %s. %r", prognam, errnam, msg, args);
 
116
        }
 
117
        return (ret);
 
118
}