migrate substitution keywords to SVN
[reactos.git] / reactos / lib / kjs / micros / w32.c
1 /*
2 * W32 specific functions.
3 * Copyright (c) 1998 New Generation Software (NGS) Oy
4 *
5 * Author: Markku Rossi <mtr@ngs.fi>
6 */
7
8 /*
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
18 *
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the Free
21 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * MA 02111-1307, USA
23 */
24
25 /*
26 * $Source: /cygdrive/c/RCVS/CVS/ReactOS/reactos/lib/kjs/micros/w32.c,v $
27 * $Id$
28 */
29
30 #include <jsint.h>
31
32 #define WIN32_LEAN_AND_MEAN
33 #include <windows.h>
34
35 /*
36 * Global functions.
37 */
38
39 unsigned int
40 sleep (unsigned int seconds)
41 {
42 Sleep ((ULONG) seconds * 1000);
43
44 /* XXX Should count how many seconcs we actually slept and return it. */
45 return 0;
46 }
47
48
49 int
50 usleep (unsigned int useconds)
51 {
52 Sleep (useconds);
53 return 0;
54 }
55
56
57 /*
58 * Directory handling.
59 */
60
61 DIR *
62 opendir (const char *name)
63 {
64 DIR *dir;
65
66 dir = calloc (1, sizeof (*dir));
67 if (dir == NULL)
68 return NULL;
69
70 dir->path = malloc (strlen (name) + 5);
71 if (dir->path == NULL)
72 {
73 free (dir);
74 return NULL;
75 }
76 sprintf (dir->path, "%s\\*.*", name);
77
78 dir->handle = _findfirst (dir->path, &dir->finddata);
79 dir->pos = 0;
80
81 return dir;
82 }
83
84
85 struct dirent *
86 readdir (DIR *dir)
87 {
88 switch (dir->pos)
89 {
90 case 0:
91 dir->de.d_name = ".";
92 break;
93
94 case 1:
95 dir->de.d_name = "..";
96 break;
97
98 case 2:
99 if (dir->handle < 0)
100 /* It was an empty directory. */
101 return NULL;
102
103 dir->de.d_name = dir->finddata.name;
104 break;
105
106 default:
107 if (_findnext (dir->handle, &dir->finddata) < 0)
108 return NULL;
109
110 dir->de.d_name = dir->finddata.name;
111 break;
112 }
113
114 dir->pos++;
115
116 return &dir->de;
117 }
118
119
120 int
121 closedir (DIR *dir)
122 {
123 _findclose (dir->handle);
124 free (dir->path);
125 free (dir);
126
127 return 0;
128 }
129
130
131 void
132 rewinddir (DIR *dir)
133 {
134 _findclose (dir->handle);
135
136 dir->pos = 0;
137 dir->handle = _findfirst (dir->path, &dir->finddata);
138 }
139
140
141 void
142 seekdir (DIR *dir, long offset)
143 {
144 }
145
146 long
147 telldir (DIR *dir)
148 {
149 return -1;
150 }