os_win32.c File Reference

wpa_supplicant/hostapd / OS specific functions for Win32 systems More...

#include "includes.h"
#include <winsock2.h>
#include <wincrypt.h>
#include "os.h"
Include dependency graph for os_win32.c:

Go to the source code of this file.

Defines

#define EPOCHFILETIME   (116444736000000000ULL)

Functions

void os_sleep (os_time_t sec, os_time_t usec)
 Sleep (sec, usec).
int os_get_time (struct os_time *t)
 Get current time (sec, usec).
int os_mktime (int year, int month, int day, int hour, int min, int sec, os_time_t *t)
 Convert broken-down time into seconds since 1970-01-01.
int os_daemonize (const char *pid_file)
 Run in the background (detach from the controlling terminal).
void os_daemonize_terminate (const char *pid_file)
 Stop running in the background (remove pid file).
int os_get_random (unsigned char *buf, size_t len)
 Get cryptographically strong pseudo random data.
unsigned long os_random (void)
 Get pseudo random value (not necessarily very strong).
char * os_rel2abs_path (const char *rel_path)
 Get an absolute path for a file.
int os_program_init (void)
 Program initialization (called at start).
void os_program_deinit (void)
 Program deinitialization (called just before exit).
int os_setenv (const char *name, const char *value, int overwrite)
 Set environment variable.
int os_unsetenv (const char *name)
 Delete environent variable.
char * os_readfile (const char *name, size_t *len)
 Read a file to an allocated memory buffer.
void * os_zalloc (size_t size)
 Allocate and zero memory.
size_t os_strlcpy (char *dest, const char *src, size_t siz)
 Copy a string with size bound and NUL-termination.

Detailed Description

wpa_supplicant/hostapd / OS specific functions for Win32 systems

Copyright
Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.

Alternatively, this software may be distributed under the terms of BSD license.

See README and COPYING for more details.

Definition in file os_win32.c.


Function Documentation

int os_daemonize ( const char *  pid_file  ) 

Run in the background (detach from the controlling terminal).

Parameters:
pid_file File name to write the process ID to or NULL to skip this
Returns:
0 on success, -1 on failure

Definition at line 96 of file os_win32.c.

void os_daemonize_terminate ( const char *  pid_file  ) 

Stop running in the background (remove pid file).

Parameters:
pid_file File name to write the process ID to or NULL to skip this

Definition at line 103 of file os_win32.c.

int os_get_random ( unsigned char *  buf,
size_t  len 
)

Get cryptographically strong pseudo random data.

Parameters:
buf Buffer for pseudo random data
len Length of the buffer
Returns:
0 on success, -1 on failure

Definition at line 108 of file os_win32.c.

int os_get_time ( struct os_time t  ) 

Get current time (sec, usec).

Parameters:
t Pointer to buffer for the time
Returns:
0 on success, -1 on failure

Definition at line 31 of file os_win32.c.

int os_mktime ( int  year,
int  month,
int  day,
int  hour,
int  min,
int  sec,
os_time_t *  t 
)

Convert broken-down time into seconds since 1970-01-01.

Parameters:
year Four digit year
month Month (1 .. 12)
day Day of month (1 .. 31)
hour Hour (0 .. 23)
min Minute (0 .. 59)
sec Second (0 .. 60)
t Buffer for returning calendar time representation (seconds since 1970-01-01 00:00:00)
Returns:
0 on success, -1 on failure

Note: The result is in seconds from Epoch, i.e., in UTC, not in local time which is used by POSIX mktime().

Definition at line 56 of file os_win32.c.

void os_program_deinit ( void   ) 

Program deinitialization (called just before exit).

This function is called just before a program exists. If there are any OS specific processing, e.g., freeing resourced allocated in os_program_init(), it should be done here. It is also acceptable for this function to do nothing.

Definition at line 149 of file os_win32.c.

int os_program_init ( void   ) 

Program initialization (called at start).

Returns:
0 on success, -1 on failure

This function is called when a programs starts. If there are any OS specific processing that is needed, it can be placed here. It is also acceptable to just return 0 if not special processing is needed.

Definition at line 136 of file os_win32.c.

unsigned long os_random ( void   ) 

Get pseudo random value (not necessarily very strong).

Returns:
Pseudo random value

Definition at line 124 of file os_win32.c.

char* os_readfile ( const char *  name,
size_t *  len 
)

Read a file to an allocated memory buffer.

Parameters:
name Name of the file to read
len For returning the length of the allocated buffer
Returns:
Pointer to the allocated buffer or NULL on failure

This function allocates memory and reads the given file to this buffer. Both binary and text files can be read with this function. The caller is responsible for freeing the returned buffer with os_free().

Definition at line 169 of file os_win32.c.

char* os_rel2abs_path ( const char *  rel_path  ) 

Get an absolute path for a file.

Parameters:
rel_path Relative path to a file
Returns:
Absolute path for the file or NULL on failure

This function tries to convert a relative path of a file to an absolute path in order for the file to be found even if current working directory has changed. The returned value is allocated and caller is responsible for freeing it. It is acceptable to just return the same path in an allocated buffer, e.g., return strdup(rel_path). This function is only used to find configuration files when os_daemonize() may have changed the current working directory and relative path would be pointing to a different location.

Definition at line 130 of file os_win32.c.

int os_setenv ( const char *  name,
const char *  value,
int  overwrite 
)

Set environment variable.

Parameters:
name Name of the variable
value Value to set to the variable
overwrite Whether existing variable should be overwritten
Returns:
0 on success, -1 on error

This function is only used for wpa_cli action scripts. OS wrapper does not need to implement this if such functionality is not needed.

Definition at line 157 of file os_win32.c.

void os_sleep ( os_time_t  sec,
os_time_t  usec 
)

Sleep (sec, usec).

Parameters:
sec Number of seconds to sleep
usec Number of microseconds to sleep

Definition at line 22 of file os_win32.c.

size_t os_strlcpy ( char *  dest,
const char *  src,
size_t  siz 
)

Copy a string with size bound and NUL-termination.

Parameters:
dest Destination
src Source
siz Size of the target buffer
Returns:
Total length of the target string (length of src) (not including NUL-termination)

This function matches in behavior with the strlcpy(3) function in OpenBSD.

Definition at line 201 of file os_win32.c.

int os_unsetenv ( const char *  name  ) 

Delete environent variable.

Parameters:
name Name of the variable
Returns:
0 on success, -1 on error

This function is only used for wpa_cli action scripts. OS wrapper does not need to implement this if such functionality is not needed.

Definition at line 163 of file os_win32.c.

void* os_zalloc ( size_t  size  ) 

Allocate and zero memory.

Parameters:
size Number of bytes to allocate
Returns:
Pointer to allocated and zeroed memory or NULL on failure

Caller is responsible for freeing the returned buffer with os_free().

Definition at line 195 of file os_win32.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on Sat Nov 21 23:23:47 2009 for hostapd by  doxygen 1.6.1