2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /* functions for DJGPP to write to DOS memory or duplicate Win32 functions. */
13 #include <sys/farptr.h>
16 #include "dosdefs95.h"
18 #define MIN(a, b) ((a) < (b) ? (a) : (b))
20 dos_memset(dos_ptr offset, int val, int size)
24 for (i = 0; i < size; i++)
26 _farpokeb(_dos_ds, offset++, val);
30 char *dos_strcpy_get(char *str, unsigned int offset)
34 while ((a = _farpeekb(_dos_ds, offset++)) != 0)
41 char *dos_strncpy_get(char *str, unsigned int offset, int len)
46 while ((a = _farpeekb(_dos_ds, offset++)) != 0 && n++ < len)
53 dos_ptr dos_strcpy_put(dos_ptr offset, char *str)
57 while ((a = *str++) != 0)
58 _farpokeb(_dos_ds, offset++, a);
59 _farpokeb(_dos_ds, offset, 0);
64 dos_ptr dos_strncpy_put(dos_ptr offset, char *str, int len)
69 while ((a = *str++) != 0 && n++ < len)
70 _farpokeb(_dos_ds, offset++, a);
71 _farpokeb(_dos_ds, offset, 0);
76 dos_ptr dos_strrchr(dos_ptr offset, char c)
81 while ((a = _farpeekb(_dos_ds, offset++)) != 0)
83 if (a == c) temp = offset-1;
89 int dos_strcmp(unsigned char *str, dos_ptr offset)
91 register unsigned char a, b;
93 while (((a = *str++) == (b = _farpeekb(_dos_ds, offset++))) && a && b);
97 int dos_strncmp(unsigned char *str, dos_ptr offset, int len)
99 register unsigned char a, b;
102 while (i++ < len && ((a = *str++) == (b = _farpeekb(_dos_ds, offset++))) && a && b);
106 int dos_strlen(dos_ptr offset)
110 while (_farpeekb(_dos_ds, offset++))
117 int sub_time(struct timeval a, struct timeval b)
119 int n = a.tv_sec - b.tv_sec;
121 n += a.tv_usec - b.tv_usec;
125 int tm_to_ms(struct timeval t)
127 int n = t.tv_sec * 1000;
128 n += t.tv_usec / 1000;
135 int n = t.tv_sec * 1000;
137 gettimeofday(&t, NULL);
138 n += t.tv_usec / 1000;
147 gettimeofday(&t, NULL);
148 n = t.tv_sec * 1000000;
153 int GetPrivateProfileString(char *sect, char *key, char *def,
154 char *buf, int len, char *file)
163 FILE *f = fopen(file, "r");
166 sprintf(sectstr, "[%s]", sect);
172 /* look for section names */
176 /* if sect is NULL, copy all section names */
179 amt = MIN(strlen(s)+1, len-1);
180 strncpy(buf, s, amt-1);
188 /* continue if non-matching section name */
189 if (sect && strnicmp(s+1, sect, strlen(sect)) != 0)
192 /* else we have the correct section */
199 /* get the key part */
201 p = strrchr(skey, '=');
202 if (!p) { fclose(f); return 0; }
205 /* continue if key doesn't match */
206 if (key && stricmp(skey, key) != 0)
209 /* if NULL key, copy key names */
212 amt = MIN(strlen(skey)+1, len-2);
213 strncpy(buf, skey, amt);
215 buf[amt+1] = 0; /* final trailing NULL */
222 /* discard key= and newline */
223 offset = strlen(key) + 1;
224 amt = MIN(strlen(s+offset)-1, len-1);
225 strncpy(buf, s+offset, amt);
238 nchars = strlen(def);
246 int WritePrivateProfileString(char *sect, char *key, char *str, char *file)
248 char tmpfile[256], s[256], sectstr[256];
251 FILE *fr = fopen(file, "r");
252 FILE *fw = fopen(tmpfile, "w");
254 strcpy(tmpfile, file);
255 p = strrchr(tmpfile, '.');
257 strcat(tmpfile, ".tmp"); /* change extension to .tmp */
259 sprintf(sectstr, "[%s]", sect);
267 /* look for section names */
268 if (found || s[0] != '[')
273 if (stricmp(s, sectstr) == 0)
275 /* found section, print new item */
287 /* delete old file */
291 rename(tmpfile, file);