| [2] | 1 | /*************************************************************** |
|---|
| 2 | ** |
|---|
| 3 | ** Broadcom Corp. Confidential |
|---|
| 4 | ** Copyright 1998-2000 Broadcom Corp. All Rights Reserved. |
|---|
| 5 | ** |
|---|
| 6 | ** THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED |
|---|
| 7 | ** SOFTWARE LICENSE AGREEMENT BETWEEN THE USER AND BROADCOM. |
|---|
| 8 | ** YOU HAVE NO RIGHT TO USE OR EXPLOIT THIS MATERIAL EXCEPT |
|---|
| 9 | ** SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 10 | ** |
|---|
| 11 | ** File: ministd.h |
|---|
| 12 | ** Description: subset of standard c functions. |
|---|
| 13 | ** |
|---|
| 14 | ** Created: 06/07/04 by Jeff Fisher |
|---|
| 15 | ** |
|---|
| 16 | ** |
|---|
| 17 | ** |
|---|
| 18 | ****************************************************************/ |
|---|
| 19 | |
|---|
| 20 | #ifndef __BCM_MINISTD_H__ |
|---|
| 21 | #define __BCM_MINISTD_H__ |
|---|
| 22 | |
|---|
| 23 | #include "bos.h" |
|---|
| 24 | |
|---|
| 25 | #ifdef __cplusplus |
|---|
| 26 | extern "C" |
|---|
| 27 | { |
|---|
| 28 | #endif |
|---|
| 29 | |
|---|
| 30 | #ifdef __NEWLIB__ |
|---|
| 31 | #include <stdlib.h> |
|---|
| 32 | #include <stdio.h> |
|---|
| 33 | #include <string.h> |
|---|
| 34 | #include <malloc.h> |
|---|
| 35 | #include <sys/time.h> |
|---|
| 36 | #include <time.h> |
|---|
| 37 | #define b_timeval struct timeval |
|---|
| 38 | #define b_tm struct tm |
|---|
| 39 | #define GETTIMEOFDAY(tv) gettimeofday(tv,NULL) |
|---|
| 40 | #ifdef LINUX |
|---|
| 41 | #include <setjmp.h> |
|---|
| 42 | #endif |
|---|
| 43 | #else /* __NEWLIB__ */ |
|---|
| 44 | |
|---|
| 45 | typedef struct jmp_buf |
|---|
| 46 | { |
|---|
| 47 | #if SUPPORT_DST_PLATFORM |
|---|
| 48 | unsigned int word[12]; /* 11 words, 44 bytes */ //BKTODO: in case of newcon2 11->12 (11->12) |
|---|
| 49 | #else |
|---|
| 50 | unsigned int word[11]; /* 11 words, 44 bytes */ |
|---|
| 51 | #endif |
|---|
| 52 | }jmp_buf; |
|---|
| 53 | |
|---|
| 54 | typedef struct b_tm |
|---|
| 55 | { |
|---|
| 56 | int tm_sec; /* Seconds. [0-60] (1 leap second) */ |
|---|
| 57 | int tm_min; /* Minutes. [0-59] */ |
|---|
| 58 | int tm_hour; /* Hours. [0-23] */ |
|---|
| 59 | int tm_mday; /* Day. [1-31] */ |
|---|
| 60 | int tm_mon; /* Month. [0-11] */ |
|---|
| 61 | int tm_year; /* Year - 1980. */ |
|---|
| 62 | int tm_wday; /* Day of week. [0-6] */ |
|---|
| 63 | int tm_yday; /* Days in year.[0-365] */ |
|---|
| 64 | }b_tm; |
|---|
| 65 | |
|---|
| 66 | #define GETTIMEOFDAY(tv) gettimeofday(tv) |
|---|
| 67 | |
|---|
| 68 | int setjmp(jmp_buf *p_jmp_buf); |
|---|
| 69 | int longjmp(jmp_buf *p_jmp_buf,int val); |
|---|
| 70 | int printf(const char *format, ...); |
|---|
| 71 | int snprintf(char *str, size_t size, const char *format, ...); |
|---|
| 72 | int vsnprintf(char *buf, size_t size, const char *fmt, va_list args); |
|---|
| 73 | void *memset(void *s, int c, size_t n); |
|---|
| 74 | int memcmp(const void *src,const void *dest,size_t count); |
|---|
| 75 | void *memcpy(void *dest, const void *src, size_t n); |
|---|
| 76 | char *strcpy(char *dest, const char *src); |
|---|
| 77 | char *strncpy(char *dest, const char *src, size_t n); |
|---|
| 78 | size_t strlen(const char * str); |
|---|
| 79 | int getchar(void); |
|---|
| 80 | char *gets(char *s); |
|---|
| 81 | char *ngets(char *s,int len); |
|---|
| 82 | int sscanf(char* buf, char* fmt, unsigned int * val); |
|---|
| 83 | int strcmp( const char * first,const char * last); |
|---|
| 84 | int strncmp(const char *s1, const char *s2, int n); |
|---|
| 85 | size_t strnlen(const char * s, size_t count); |
|---|
| 86 | int perror(const char *str); |
|---|
| 87 | void gettimeofday(b_timeval *tv); |
|---|
| 88 | int fprintf(int* f, const char *format, ...); |
|---|
| 89 | |
|---|
| 90 | #define getc getchar |
|---|
| 91 | #if 0 |
|---|
| 92 | unsigned int ReadReg32(unsigned int offset); |
|---|
| 93 | void WriteReg32(unsigned int offset, unsigned int value); |
|---|
| 94 | #endif |
|---|
| 95 | |
|---|
| 96 | #define RAND_MAX 1000 |
|---|
| 97 | unsigned int rand(void); |
|---|
| 98 | void srand(unsigned int seed); |
|---|
| 99 | |
|---|
| 100 | #ifndef offsetof |
|---|
| 101 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER) |
|---|
| 102 | #endif |
|---|
| 103 | |
|---|
| 104 | #endif /* __NEWLIB__ */ |
|---|
| 105 | |
|---|
| 106 | #ifndef NEXUS_LINUXUSER |
|---|
| 107 | #ifdef BCM_DEBUG |
|---|
| 108 | void *malloc_align_dbg(size_t size,char alignbits, char* file, int line); |
|---|
| 109 | void *malloc_dbg(size_t size, char* file, int line); |
|---|
| 110 | void free_dbg(void *ptr, char* file, int line); |
|---|
| 111 | #define malloc(size) malloc_dbg(size,__FILE__,__LINE__) |
|---|
| 112 | #define malloc_align(size,align) malloc_align_dbg(size,align,__FILE__,__LINE__) |
|---|
| 113 | #define free(ptr) free_dbg(ptr,__FILE__,__LINE__) |
|---|
| 114 | #else |
|---|
| 115 | void *malloc_align(size_t size,char alignbits); |
|---|
| 116 | void *malloc(size_t size); |
|---|
| 117 | void free(void *ptr); |
|---|
| 118 | #endif |
|---|
| 119 | #endif |
|---|
| 120 | |
|---|
| 121 | void console_init(volatile void *uart); |
|---|
| 122 | void console_shutdown(void); |
|---|
| 123 | void console_flush(void); |
|---|
| 124 | void m_report(void); |
|---|
| 125 | int m_uncompress(unsigned char *in_buf, unsigned int in_size, |
|---|
| 126 | unsigned char * out_buf, unsigned int out_size); |
|---|
| 127 | void utctime(unsigned int secs, b_tm *p_tm); |
|---|
| 128 | |
|---|
| 129 | #if SUPPORT_DST_PLATFORM |
|---|
| 130 | void *memmove(void *dest, const void *src, size_t n); |
|---|
| 131 | char *strchr(const char *str, int c); |
|---|
| 132 | int sprintf(char *str, const char *format, ...); |
|---|
| 133 | char *strcat(char *dest, const char *src); |
|---|
| 134 | char *strstr(const char *s, const char *s2); |
|---|
| 135 | //int getch(int timeout_ms); |
|---|
| 136 | #define stderr 1 |
|---|
| 137 | typedef void *FILE; |
|---|
| 138 | int fprintf(int* f, const char *format, ...); |
|---|
| 139 | size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream); |
|---|
| 140 | size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); |
|---|
| 141 | FILE *fopen(const char *path, const char *mode); |
|---|
| 142 | int fclose(FILE *stream); |
|---|
| 143 | int fseek(FILE *stream, long offset, int whence); |
|---|
| 144 | long ftell(FILE *stream); |
|---|
| 145 | int fflush(FILE *stream); |
|---|
| 146 | #ifndef EOF |
|---|
| 147 | #define EOF (-1) |
|---|
| 148 | #endif |
|---|
| 149 | #ifndef SEEK_SET |
|---|
| 150 | # define SEEK_SET 0 /* Seek from beginning of file. */ |
|---|
| 151 | #endif |
|---|
| 152 | #ifndef SEEK_CUR |
|---|
| 153 | # define SEEK_CUR 1 /* Seek from current position. */ |
|---|
| 154 | #endif |
|---|
| 155 | #ifndef SEEK_END |
|---|
| 156 | # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ |
|---|
| 157 | #endif |
|---|
| 158 | |
|---|
| 159 | #define vsprintf(buf,fmt,args) vsnprintf(buf,4096,fmt,args) |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | #endif |
|---|
| 163 | |
|---|
| 164 | #define RAND_INT(x) (((x) * rand())/RAND_MAX) |
|---|
| 165 | |
|---|
| 166 | #ifdef __cplusplus |
|---|
| 167 | } |
|---|
| 168 | #endif |
|---|
| 169 | |
|---|
| 170 | #endif /* __BCM_MINISTD_H__ */ |
|---|
| 171 | |
|---|