Subversion Repositories Kolibri OS

Rev

Rev 4874 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4874 Rev 4921
Line 1... Line 1...
1
/* Reentrant versions of lseek system call. */
1
/* Reentrant versions of lseek system call. */
Line 2... Line 2...
2
 
2
 
3
#include 
3
#include 
4
#include 
4
#include 
5
#include <_syslist.h>
-
 
Line 6... Line 5...
6
#include 
5
#include <_syslist.h>
7
 
6
 
Line 8... Line 7...
8
/* Some targets provides their own versions of this functions.  Those
7
/* Some targets provides their own versions of this functions.  Those
Line 14... Line 13...
14
#endif
13
#endif
15
#endif
14
#endif
Line 16... Line 15...
16
 
15
 
Line 17... Line 16...
17
#ifndef REENTRANT_SYSCALLS_PROVIDED
16
#ifndef REENTRANT_SYSCALLS_PROVIDED
18
 
17
 
19
#pragma pack(push, 1)
-
 
20
typedef struct
-
 
21
{
-
 
22
  char sec;
-
 
23
  char min;
-
 
24
  char hour;
-
 
25
  char rsv;
-
 
26
}detime_t;
-
 
27
 
-
 
28
typedef struct
-
 
29
{
-
 
30
  char  day;
-
 
31
  char  month;
-
 
32
  short year;
-
 
33
}dedate_t;
-
 
34
 
-
 
35
typedef struct
-
 
36
{
-
 
37
  unsigned    attr;
-
 
38
  unsigned    flags;
-
 
39
  union
-
 
40
  {
-
 
41
     detime_t  ctime;
-
 
42
     unsigned  cr_time;
-
 
43
  };
-
 
44
  union
-
 
45
  {
-
 
46
     dedate_t  cdate;
-
 
47
     unsigned  cr_date;
-
 
48
  };
-
 
49
  union
-
 
50
  {
-
 
51
     detime_t  atime;
-
 
52
     unsigned  acc_time;
-
 
53
  };
-
 
54
  union
-
 
55
  {
-
 
56
     dedate_t  adate;
-
 
57
     unsigned  acc_date;
-
 
58
  };
-
 
59
  union
-
 
60
  {
-
 
61
     detime_t  mtime;
-
 
62
     unsigned  mod_time;
-
 
63
  };
-
 
64
  union
-
 
65
  {
-
 
66
     dedate_t  mdate;
-
 
67
     unsigned  mod_date;
-
 
68
  };
-
 
69
  unsigned    size;
-
 
70
  unsigned    size_high;
-
 
71
} FILEINFO;
-
 
72
 
-
 
73
#pragma pack(pop)
-
 
74
 
18
/* We use the errno variable used by the system dependent layer.  */
75
 
-
 
76
extern unsigned  __NFiles;
-
 
77
 
-
 
78
#define __handle_check( __h, __r )                \
-
 
79
        if( (__h) < 0  ||  (__h) > __NFiles ) {   \
-
 
80
           ptr->_errno =  EBADF ;                 \
-
 
81
           return( __r );                         \
-
 
Line 82... Line 19...
82
        }
19
#undef errno
83
 
20
extern int errno;
84
 
21
 
Line 114... Line 51...
114
     int fd _AND
51
     int fd _AND
115
     _off_t pos _AND
52
     _off_t pos _AND
116
     int whence)
53
     int whence)
117
{
54
{
118
    _off_t ret;
55
  _off_t ret;
119
    __file_handle *fh;
-
 
Line 120... Line -...
120
 
-
 
121
    __handle_check( fd, -1 );
-
 
122
    fh = (__file_handle*) __getOSHandle( fd );
-
 
123
 
-
 
124
    switch(whence)
-
 
125
    {
-
 
126
        case SEEK_SET:
-
 
127
            ret = pos;
-
 
128
            break;
-
 
129
        case SEEK_CUR:
-
 
130
            ret = fh->offset + pos;
-
 
131
            break;
-
 
132
        case SEEK_END:
56
 
133
        {
-
 
134
            FILEINFO info;
57
  errno = 0;
135
            get_fileinfo(fh->name, &info);
58
  if ((ret = _lseek (fd, pos, whence)) == (_off_t) -1 && errno != 0)
136
            ret = pos + info.size;
59
    ptr->_errno = errno;
137
            break;
60
  return ret;
138
        }
-
 
139
        default:
-
 
140
            ptr->_errno = EINVAL;
-
 
141
            return -1;
-
 
142
    };
-
 
143
 
-
 
144
    fh->offset = ret;
-
 
145
 
-
 
146
    return( ret );
-
 
147
}
-
 
148
 
-
 
149
_off_t
-
 
150
_DEFUN (lseek, (fd, pos, whence),
-
 
151
     int fd _AND
-
 
152
     _off_t pos _AND
-
 
153
     int whence)
-
 
154
 
-
 
155
{
-
 
156
    return _lseek_r(_REENT, fd, pos, whence);
-
 
Line 157... Line 61...
157
};
61
}