• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*!
2  * \copy
3  *     Copyright (c)  2010-2013, Cisco Systems
4  *     All rights reserved.
5  *
6  *     Redistribution and use in source and binary forms, with or without
7  *     modification, are permitted provided that the following conditions
8  *     are met:
9  *
10  *        * Redistributions of source code must retain the above copyright
11  *          notice, this list of conditions and the following disclaimer.
12  *
13  *        * Redistributions in binary form must reproduce the above copyright
14  *          notice, this list of conditions and the following disclaimer in
15  *          the documentation and/or other materials provided with the
16  *          distribution.
17  *
18  *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  *     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  *     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  *     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  *     COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24  *     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  *     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  *     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28  *     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  *     POSSIBILITY OF SUCH DAMAGE.
30  *
31  *
32  * \file    crt_util_safe_x.h
33  *
34  * \brief   Safe CRT like util for cross platfroms support
35  *
36  * \date    06/04/2010 Created
37  *
38  *************************************************************************************
39  */
40 #ifndef WELS_CRT_UTIL_SAFE_CROSS_PLATFORMS_H__
41 #define WELS_CRT_UTIL_SAFE_CROSS_PLATFORMS_H__
42 
43 #include <string.h>
44 #include <stdlib.h>
45 #include <stdarg.h>
46 #include <stdio.h>
47 #include <math.h>
48 #include <time.h>
49 
50 #if defined(_WIN32)
51 #include <windows.h>
52 #include <sys/types.h>
53 #include <sys/timeb.h>
54 #else
55 #include <sys/time.h>
56 #include "typedefs.h"
57 #endif//_WIN32
58 
59 #include "typedefs.h"
60 
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 
65 #define     WELS_FILE_SEEK_SET           SEEK_SET
66 #define     WELS_FILE_SEEK_CUR           SEEK_CUR
67 #define     WESL_FILE_SEEK_END           SEEK_END
68 
69 typedef      FILE  WelsFileHandle;
70 
71 #ifdef _WIN32
72 typedef      struct _timeb     SWelsTime;
73 #else
74 typedef struct TagWelsTime {
75   time_t time;
76   unsigned short millitm;
77 } SWelsTime;
78 #endif
79 
80 int32_t   WelsSnprintf (char* buffer,  int32_t sizeOfBuffer,  const char* format, ...);
81 char*   WelsStrncpy (char* dest, int32_t sizeInBytes, const char* src);
82 char*   WelsStrcat (char* dest, uint32_t sizeInBytes, const char* src);
83 int32_t   WelsVsnprintf (char* buffer, int32_t sizeOfBuffer, const char* format, va_list argptr);
84 
85 WelsFileHandle*        WelsFopen (const char* filename,  const char* mode);
86 int32_t                WelsFclose (WelsFileHandle*   fp);
87 int32_t                WelsFread (void* buffer, int32_t size, int32_t count, WelsFileHandle* fp);
88 int32_t                WelsFwrite (const void* buffer, int32_t size, int32_t count, WelsFileHandle* fp);
89 int32_t                WelsFseek (WelsFileHandle* fp, int32_t offset, int32_t origin);
90 int32_t                WelsFflush (WelsFileHandle* fp);
91 
92 int32_t                WelsGetTimeOfDay (SWelsTime* tp);
93 int32_t                WelsStrftime (char* buffer, int32_t size, const char* format, const SWelsTime* tp);
94 uint16_t               WelsGetMillisecond (const SWelsTime* tp);
95 
96 
97 #ifdef __cplusplus
98 }
99 #endif
100 
101 #endif//WELS_CRT_UTIL_SAFE_CROSS_PLATFORMS_H__
102