annotate src/osdep/dos/fdstring.c @ 0:ada5e610ab86

imap-2007e
author yuuji@gentei.org
date Mon, 14 Sep 2009 15:17:45 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1 /* ========================================================================
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
2 * Copyright 1988-2007 University of Washington
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
3 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
4 * Licensed under the Apache License, Version 2.0 (the "License");
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
5 * you may not use this file except in compliance with the License.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
6 * You may obtain a copy of the License at
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
7 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
8 * http://www.apache.org/licenses/LICENSE-2.0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
9 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
10 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
11 * ========================================================================
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
12 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
13
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
14 /*
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
15 * Program: File descriptor string routines
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
16 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
17 * Author: Mark Crispin
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
18 * Networks and Distributed Computing
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
19 * Computing & Communications
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
20 * University of Washington
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
21 * Administration Building, AG-44
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
22 * Seattle, WA 98195
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
23 * Internet: MRC@CAC.Washington.EDU
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
24 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
25 * Date: 15 April 1997
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
26 * Last Edited: 4 April 2007
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
27 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
28
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
29 #include "mail.h"
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
30 #include "osdep.h"
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
31 #include "misc.h"
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
32 #include "fdstring.h"
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
33
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
34 /* String driver for fd stringstructs */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
35
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
36 static void fd_string_init (STRING *s,void *data,unsigned long size);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
37 static char fd_string_next (STRING *s);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
38 static void fd_string_setpos (STRING *s,unsigned long i);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
39
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
40 STRINGDRIVER fd_string = {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
41 fd_string_init, /* initialize string structure */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
42 fd_string_next, /* get next byte in string structure */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
43 fd_string_setpos /* set position in string structure */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
44 };
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
45
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
46
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
47 /* Initialize string structure for fd stringstruct
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
48 * Accepts: string structure
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
49 * pointer to string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
50 * size of string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
51 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
52
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
53 static void fd_string_init (STRING *s,void *data,unsigned long size)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
54 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
55 FDDATA *d = (FDDATA *) data;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
56 /* note fd */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
57 s->data = (void *) (unsigned long) d->fd;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
58 s->data1 = d->pos; /* note file offset */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
59 s->size = size; /* note size */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
60 s->curpos = s->chunk = d->chunk;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
61 s->chunksize = (unsigned long) d->chunksize;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
62 s->offset = 0; /* initial position */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
63 /* and size of data */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
64 s->cursize = min (s->chunksize,size);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
65 /* move to that position in the file */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
66 lseek (d->fd,d->pos,L_SET);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
67 read (d->fd,s->chunk,(size_t) s->cursize);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
68 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
69
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
70 /* Get next character from fd stringstruct
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
71 * Accepts: string structure
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
72 * Returns: character, string structure chunk refreshed
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
73 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
74
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
75 static char fd_string_next (STRING *s)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
76 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
77 char c = *s->curpos++; /* get next byte */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
78 SETPOS (s,GETPOS (s)); /* move to next chunk */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
79 return c; /* return the byte */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
80 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
81
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
82
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
83 /* Set string pointer position for fd stringstruct
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
84 * Accepts: string structure
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
85 * new position
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
86 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
87
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
88 static void fd_string_setpos (STRING *s,unsigned long i)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
89 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
90 if (i > s->size) i = s->size; /* don't permit setting beyond EOF */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
91 s->offset = i; /* set new offset */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
92 s->curpos = s->chunk; /* reset position */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
93 /* set size of data */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
94 if (s->cursize = min (s->chunksize,SIZE (s))) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
95 /* move to that position in the file */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
96 lseek ((long) s->data,s->data1 + s->offset,L_SET);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
97 read ((long) s->data,s->curpos,(size_t) s->cursize);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
98 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
99 }

yatex.org