Xively Official / mbed-libxively-5d6fdd4

Dependents:   xively-jumpstart-demo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers xi_helpers.h Source File

xi_helpers.h

Go to the documentation of this file.
00001 // Copyright (c) 2003-2013, LogMeIn, Inc. All rights reserved.
00002 // This is part of Xively C library, it is under the BSD 3-Clause license.
00003 
00004 /**
00005  * \file    xi_helpers.h
00006  * \author  Olgierd Humenczuk
00007  * \brief   General helpers used by the library
00008  */
00009 
00010 #ifndef __XI_HELPERS_H__
00011 #define __XI_HELPERS_H__
00012 
00013 #include <stdlib.h>
00014 #include <time.h>
00015 #include <limits.h>
00016 
00017 #ifdef __cplusplus
00018 extern "C" {
00019 #endif
00020 
00021 /**
00022  * \note    Needed to avoid using `strdup()` which can cause some problems with `free()`,
00023  *          because of buggy `realloc()` implementations.
00024  *
00025  * \return  Duplicated string or null in case of memory allocation problem.
00026  */
00027 char* xi_str_dup ( const char* s );
00028 
00029 /**
00030  * \brief   Copies `src` string into `dst`, but stops whenever `delim` is reached or the `dst_size` is exceeded
00031  *
00032  * \return  Number of copied characters or -1 if an error occurred.
00033  */
00034 int xi_str_copy_untiln( char* dst, size_t dst_size, const char* src, char delim );
00035 
00036 /**
00037  * \brief   Converts from `tm` to `time_t`
00038  *
00039  * \note    This code assumes that unsigned long can be converted to `time_t`.
00040  *          A `time_t` should not be wider than `unsigned long`, since this
00041  *          would mean that the check for overflow at the end could fail.
00042  *
00043  * \note    This implementation had been copied from MINIX C library.
00044  *          Which is 100% compatible with our license.
00045  *
00046  * \note    This function does not take into account the timezone or the `dst`,
00047  *          it just converts `tm` structure using date and time fields (i.e. UTC).
00048  */
00049 time_t xi_mktime( struct tm* t );
00050 
00051 /**
00052  * \brief   This just wraps system's `gmtime()`, it a facade for future use
00053  */
00054 struct tm* xi_gmtime( time_t* t );
00055 
00056 /**
00057  * \brief   Replaces `p` with `r` for every `p` in `buffer`
00058  *
00059  * \return  Pointer to converted buffer.
00060  * \note    This function assumes that the buffer is terminated with `\0`.
00061  */
00062 char* xi_replace_with(
00063       char p, char r
00064     , char* buffer
00065     , size_t max_chars );
00066 
00067 #ifdef __cplusplus
00068 }
00069 #endif
00070 
00071 #endif // __XI_HELPERS_H__