Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/runtime/c-libs/unix-raise-syserr.c
ViewVC logotype

Annotation of /sml/trunk/src/runtime/c-libs/unix-raise-syserr.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 249 - (view) (download) (as text)
Original Path: sml/branches/SMLNJ/src/runtime/c-libs/unix-raise-syserr.c

1 : monnier 249 /* unix-raise-syserr.c
2 :     *
3 :     * COPYRIGHT (c) 1995 by AT&T Bell Laboratories.
4 :     */
5 :    
6 :     #include "ml-unixdep.h"
7 :     #ifdef HAS_STRERROR
8 :     # include <string.h>
9 :     #endif
10 :     #include <errno.h>
11 :     #include "ml-base.h"
12 :     #include "ml-state.h"
13 :     #include "ml-objects.h"
14 :     #include "ml-globals.h"
15 :     #include "ml-c.h"
16 :    
17 :    
18 :     #ifndef HAS_STRERROR
19 :     /* strerror:
20 :     * An implementation of strerror for those systems that do not provide it.
21 :     */
22 :     PVT char *strerror (int errnum)
23 :     {
24 :     extern int sys_nerr;
25 :     extern char *sys_errlist[];
26 :    
27 :     if ((errnum < 0) || (sys_nerr <= errnum))
28 :     return "<unknown system error>";
29 :     else
30 :     return sys_errlist[errnum];
31 :    
32 :     } /* end of strerror */
33 :     #endif
34 :    
35 :    
36 :     /* RaiseSysError:
37 :     *
38 :     * Raise the ML exception SysErr, which has the spec:
39 :     *
40 :     * exception SysErr of (string * syserror option)
41 :     *
42 :     * For the time being, we use the errno value as the syserror; eventually that
43 :     * will be represented by an (int * string) pair. If alt_msg is non-zero,
44 :     * then use it as the error string and use NONE for the syserror.
45 :     */
46 :     ml_val_t RaiseSysError (ml_state_t *msp, const char *altMsg, const char *at)
47 :     {
48 :     ml_val_t s, atStk, syserror, arg, exn;
49 :     const char *msg;
50 :     char buf[32];
51 :    
52 :     if (altMsg != NIL(char *)) {
53 :     msg = altMsg;
54 :     syserror = OPTION_NONE;
55 :     }
56 :     else if ((msg = strerror(errno)) != NIL(char *)) {
57 :     OPTION_SOME(msp, syserror, INT_CtoML(errno))
58 :     }
59 :     else {
60 :     sprintf(buf, "<unknown error %d>", errno);
61 :     msg = buf;
62 :     OPTION_SOME(msp, syserror, INT_CtoML(errno));
63 :     }
64 :    
65 :     #if (defined(DEBUG_OS_INTERFACE) || defined(DEBUG_TRACE_CCALL))
66 :     SayDebug ("RaiseSysError: errno = %d, msg = \"%s\"\n",
67 :     (altMsg != NIL(char *)) ? -1 : errno, msg);
68 :     #endif
69 :    
70 :     s = ML_CString (msp, msg);
71 :     if (at != NIL(char *)) {
72 :     ml_val_t atMsg = ML_CString (msp, at);
73 :     LIST_cons(msp, atStk, atMsg, LIST_nil);
74 :     }
75 :     else
76 :     atStk = LIST_nil;
77 :     REC_ALLOC2 (msp, arg, s, syserror);
78 :     EXN_ALLOC (msp, exn, PTR_CtoML(SysErrId), arg, atStk);
79 :    
80 :     RaiseMLExn (msp, exn);
81 :    
82 :     return exn;
83 :    
84 :     } /* end of RaiseSysError */

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0