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

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 : monnier 223 ml_val_t vec, res;
25 : monnier 2 int n;
26 :    
27 : monnier 223 if (nbytes == 0)
28 :     return ML_string0;
29 :    
30 : monnier 2 /* allocate the vector; note that this might cause a GC */
31 : monnier 223 vec = ML_AllocRaw32 (msp, BYTES_TO_WORDS(nbytes));
32 : monnier 2 n = read (fd, PTR_MLtoC(char, vec), nbytes);
33 :     if (n < 0)
34 : monnier 8 return RAISE_SYSERR(msp, n);
35 : monnier 223 else if (n == 0)
36 :     return ML_string0;
37 : monnier 2
38 :     if (n < nbytes) {
39 : monnier 223 /* we need to shrink the vector */
40 :     ML_ShrinkRaw32 (msp, vec, BYTES_TO_WORDS(n));
41 : monnier 2 }
42 :    
43 : monnier 223 SEQHDR_ALLOC (msp, res, DESC_string, vec, n);
44 : monnier 2
45 : monnier 223 return res;
46 :    
47 : monnier 2 } /* end of _ml_P_IO_read */

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