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/posix-io/read.c
ViewVC logotype

Annotation of /sml/trunk/src/runtime/c-libs/posix-io/read.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (view) (download) (as text)
Original Path: sml/branches/SMLNJ/src/runtime/c-libs/posix-io/read.c

1 : monnier 2 /* read.c
2 :     *
3 :     * COPYRIGHT (c) 1995 by AT&T Bell Laboratories.
4 :     */
5 :    
6 :     #include "ml-unixdep.h"
7 :     #include <unistd.h>
8 :     #include "ml-base.h"
9 :     #include "ml-values.h"
10 :     #include "ml-objects.h"
11 :     #include "ml-c.h"
12 :     #include "cfun-proto-list.h"
13 :    
14 :     /* _ml_P_IO_read : (int * int) -> Word8Vector.vector
15 :     * fd nbytes
16 :     *
17 :     * Read the specified number of bytes from the specified file,
18 :     * returning them in a vector.
19 :     */
20 :     ml_val_t _ml_P_IO_read (ml_state_t *msp, ml_val_t arg)
21 :     {
22 :     int fd = REC_SELINT(arg, 0);
23 :     int nbytes = REC_SELINT(arg, 1);
24 :     ml_val_t vec;
25 :     int n;
26 :    
27 :     /* allocate the vector; note that this might cause a GC */
28 :     vec = ML_AllocString (msp, nbytes);
29 :     n = read (fd, PTR_MLtoC(char, vec), nbytes);
30 :     if (n < 0)
31 :     return RaiseSysError(msp, NIL(char *));
32 :    
33 :     if (n < nbytes) {
34 :     /* we need to correct the length in the descriptor */
35 :     PTR_MLtoC(ml_val_t, vec)[-1] = MAKE_DESC(n, DTAG_string);
36 :     }
37 :    
38 :     return vec;
39 :    
40 :     } /* end of _ml_P_IO_read */

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