EDT PDV SDK Documentation 6.2.0
edt_os_utils.h File Reference

(git e241c21fae, 2024-09-04)

#include "edt_types.h"
#include "edt_portability.h"

Functions

double edt_dtime (void)
 Return the time in seconds since the last call to edt_dtime. More...
 
double edt_timestamp (void)
 Gets the seconds + fractional seconds since the Epoch, OS independent. Uses system time; accuracy is OS dependent. More...
 
void edt_msleep (int msecs)
 Causes the process to sleep for the specified number of milliseconds. More...
 
void edt_usleep (int usecs)
 Causes process to sleep for specified number of microseconds. More...
 
void edt_free (void *ptr)
 Convenience routine to free the memory allocated with edt_alloc. More...
 
void * edt_alloc (size_t size)
 Convenience routine to allocate memory in a system-independent way. The buffer returned is page aligned. Uses VirtualAlloc on Windows NT systems, posix_memalign on UNIX-based systems. More...
 
void edt_closedir (DIRHANDLE h)
 Cross platform function to close a directory handle. More...
 
DIRHANDLE edt_opendir (const char *dirname)
 Cross platform function to open a directory for reading. More...
 
int edt_readdir (DIRHANDLE h, char *name)
 Cross platform function to read the next directory entry. More...
 
void edt_correct_slashes (char *str)
 Change the slashes in str from forward to back or vice versa depending on whether it's Windows or Unix. More...
 
void edt_fwd_to_back (char *str)
 
void edt_back_to_fwd (char *str)
 
int edt_access (const char *fname, int perm)
 Determines file access, independent of operating system. More...
 

Detailed Description

Utility functions with OS-specific implementations.

Function Documentation

◆ edt_dtime()

double edt_dtime ( void  )

Return the time in seconds since the last call to edt_dtime.

Each time edt_dtime is called, it returns the time delta since the last time it was called. Therefore the first time edt_dtime is called in a process the delta may be meaningless. Time is in seconds and fractions of a second.

This call uses system time, which is system dependent and may be too coarse for some applications. For more accurate time stamping consider the IRIG option and an external IRIG timestamp source, available with some EDT boards.

Returns
delta time, as a double floating point

◆ edt_timestamp()

double edt_timestamp ( void  )

Gets the seconds + fractional seconds since the Epoch, OS independent. Uses system time; accuracy is OS dependent.

Returns
The timestamp in seconds; a double value with tenths/hundredths/etc on the right of the decimal point.

◆ edt_msleep()

void edt_msleep ( int  msecs)

Causes the process to sleep for the specified number of milliseconds.

Parameters
msecsThe number of milliseconds for the process to sleep.
Returns
0 on success, -1 on failure. If an error occurs, call #edt_perror to get the system error message.

◆ edt_usleep()

void edt_usleep ( int  usecs)

Causes process to sleep for specified number of microseconds.

Parameters
usecsNumber of microseconds for process to sleep.
Returns
0 on success; -1 on error

◆ edt_free()

void edt_free ( void *  ptr)

Convenience routine to free the memory allocated with edt_alloc.

Parameters
ptrAddress of memory buffer to free.

◆ edt_alloc()

void * edt_alloc ( size_t  size)

Convenience routine to allocate memory in a system-independent way. The buffer returned is page aligned. Uses VirtualAlloc on Windows NT systems, posix_memalign on UNIX-based systems.

Parameters
sizeNumber of bytes of memory to allocate.
Returns
The address of the allocated memory, or NULL on error. If NULL, use #edt_perror to print the error.

◆ edt_closedir()

void edt_closedir ( DIRHANDLE  h)

Cross platform function to close a directory handle.

Parameters
hOpen directory handle.

◆ edt_opendir()

DIRHANDLE edt_opendir ( const char *  dirname)

Cross platform function to open a directory for reading.

Parameters
dirnameThe name of the directory to open.
Returns
Directory handle upon success or NULL on failure.

◆ edt_readdir()

int edt_readdir ( DIRHANDLE  h,
char *  name 
)

Cross platform function to read the next directory entry.

Parameters
hA handle for the directory, returned by edt_opendir.
nameA pointer to a string into which the name of the next file in the directory will be written. The string must be allocated by the caller to at least 256 bytes.
Returns
h if entries remain or NULL if this is the last entry.

◆ edt_correct_slashes()

void edt_correct_slashes ( char *  str)

Change the slashes in str from forward to back or vice versa depending on whether it's Windows or Unix.

Parameters
strString to process.

◆ edt_fwd_to_back()

void edt_fwd_to_back ( char *  str)

fwd_to_back: for use by edt_correct_slashes

◆ edt_back_to_fwd()

void edt_back_to_fwd ( char *  str)

back_to_fwd: for use by edt_correct_slashes

◆ edt_access()

int edt_access ( const char *  fname,
int  perm 
)

Determines file access, independent of operating system.

This a convenience routine that maps to access() on Unix/Linux systems and _access() on Windows systems.

Parameters
fnamePath name of file to check access permissions.
permPermission flag(s) to test for. See documentation for access() (Unix/Linux) or _access() (Windows) for valid values.
Returns
0 on success, -1 on failure

Example:

if(edt_access("file.ras", F_OK))
printf("Warning: overwriting file %s\n", "file.ras");