2 * wpa_supplicant/hostapd / OS specific functions for Amiga-like systems
3 * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2010-2011, Neil Cafferkey
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Alternatively, this software may be distributed under the terms of BSD
13 * See README and COPYING for more details.
22 #include <proto/dos.h>
25 void os_sleep(os_time_t sec
, os_time_t usec
)
27 ULONG ticks
= sec
* 50 + (usec
+ 19999) / 20000;
33 int os_get_time(struct os_time
*t
)
37 time((time_t *)&t
->sec
);
38 t
->usec
= ds
.ds_Tick
% TICKS_PER_SECOND
* 20000;
43 int os_mktime(int year
, int month
, int day
, int hour
, int min
, int sec
,
47 time_t t_local
, t1
, t2
;
50 if (year
< 1970 || month
< 1 || month
> 12 || day
< 1 || day
> 31 ||
51 hour
< 0 || hour
> 23 || min
< 0 || min
> 59 || sec
< 0 ||
55 memset(&tm
, 0, sizeof(tm
));
56 tm
.tm_year
= year
- 1900;
57 tm
.tm_mon
= month
- 1;
63 t_local
= mktime(&tm
);
65 /* figure out offset to UTC */
66 tm1
= localtime(&t_local
);
69 tm1
= gmtime(&t_local
);
78 *t
= (os_time_t
) t_local
- tz_offset
;
83 int os_daemonize(const char *pid_file
)
89 void os_daemonize_terminate(const char *pid_file
)
96 int os_get_random(unsigned char *buf
, size_t len
)
105 unsigned long os_random(void)
109 os_get_random((unsigned char *) &val
, sizeof(unsigned long));
115 char * os_rel2abs_path(const char *rel_path
)
117 char *buf
= NULL
, *cwd
, *ret
;
118 size_t len
= 128, cwd_len
, rel_len
, ret_len
;
121 if (strchr(rel_path
, ':') != NULL
)
122 return strdup(rel_path
);
128 cwd
= getcwd(buf
, len
);
132 if (last_errno
!= ERANGE
)
143 cwd_len
= strlen(cwd
);
144 rel_len
= strlen(rel_path
);
145 ret_len
= cwd_len
+ 1 + rel_len
+ 1;
146 ret
= malloc(ret_len
);
148 memcpy(ret
, cwd
, cwd_len
);
149 if (ret
[cwd_len
- 1] != ':')
151 memcpy(ret
+ cwd_len
+ 1, rel_path
, rel_len
);
152 ret
[ret_len
- 1] = '\0';
159 int os_program_init(void)
165 void os_program_deinit(void)
170 char * os_readfile(const char *name
, size_t *len
)
175 f
= fopen(name
, "rb");
179 fseek(f
, 0, SEEK_END
);
181 fseek(f
, 0, SEEK_SET
);
189 if (fread(buf
, 1, *len
, f
) != *len
) {
201 void * os_zalloc(size_t size
)
203 void *n
= os_malloc(size
);
205 os_memset(n
, 0, size
);
210 size_t os_strlcpy(char *dest
, const char *src
, size_t siz
)
216 /* Copy string up to the maximum size of the dest buffer */
217 while (--left
!= 0) {
218 if ((*dest
++ = *s
++) == '\0')
224 /* Not enough room for the string; force NUL-termination */
228 ; /* determine total src string length */