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 569 - (view) (download) (as text)

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

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