strigi/src/streams
compat.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifdef HAVE_CONFIG_H
00022 # include "config.h"
00023 #endif
00024
00025 #include <string.h>
00026 #include <stdlib.h>
00027 #include <ctype.h>
00028
00029
00030 #ifndef HAVE_SETENV
00031 int setenv(const char *name, const char *value, int overwrite)
00032 {
00033 int i, iRet;
00034 char * a;
00035
00036 if (!overwrite && getenv(name)) return 0;
00037
00038 i = strlen(name) + strlen(value) + 2;
00039 a = (char*)malloc(i);
00040 if (!a) return 1;
00041
00042 strcpy(a, name);
00043 strcat(a, "=");
00044 strcat(a, value);
00045
00046 iRet = putenv(a);
00047 free(a);
00048 return iRet;
00049 }
00050 #endif
00051
00052 #ifndef HAVE_STRCASECMP
00053 int strcasecmp(const char* sa, const char* sb){
00054 char ca,cb;
00055 if (sa == sb)
00056 return 0;
00057 int i=0;
00058
00059 do{
00060 ca = tolower( (*(sa++)) );
00061 cb = tolower( (*(sb++)) );
00062
00063 i++;
00064 } while ( ca != L'\0' && (ca == cb) );
00065
00066 return (int)(ca - cb);
00067 }
00068 #endif
00069
00070 #ifndef HAVE_STRNCASECMP
00071 int strncasecmp(const char* sa, const char* sb, int l){
00072 char ca,cb;
00073 if (sa == sb)
00074 return 0;
00075 int i=0;
00076
00077 do{
00078 if ( i >= l )
00079 break;
00080
00081 ca = tolower( (*(sa++)) );
00082 cb = tolower( (*(sb++)) );
00083
00084 i++;
00085 } while ( ca != L'\0' && (ca == cb) );
00086
00087 return (int)(ca - cb);
00088 }
00089 #endif
00090
00091 #ifndef HAVE_STRCASESTR
00092 const char * strcasestr(const char *big, const char *little){
00093 char* tmp1 = strdup(big);
00094 char* tmp2 = strdup(little);
00095 #ifdef HAVE_STRLWR
00096 strlwr(tmp1);
00097 strlwr(tmp2);
00098 #else
00099 char* t = tmp1;
00100 while (*t) {
00101 tolower(*t);
00102 ++t;
00103 }
00104 t = tmp2;
00105 while (*t) {
00106 tolower(*t);
00107 ++t;
00108 }
00109 #endif
00110
00111 const char * ret = strstr(tmp1,tmp2);
00112
00113 if ( ret != NULL ){
00114 ret = big + (ret-tmp1);
00115 }
00116
00117 free(tmp1);
00118 free(tmp2);
00119
00120 return ret;
00121 }
00122 #endif
00123
00124 #ifndef HAVE_ISBLANK
00125 int isblank(char c){
00126 if ( c == ' ' || c == '\t' || c == '\n' || c == '\r' )
00127 return 1;
00128
00129 return 0;
00130 }
00131 #endif
00132
00133 #ifndef HAVE_MKSTEMP
00134 #ifdef _WIN32
00135 #include <fcntl.h>
00136 #include <sys/stat.h>
00137 #endif
00138
00139 int mkstemp(char *tmpl)
00140 {
00141 mktemp(tmpl);
00142 return open(tmpl,O_RDWR|O_BINARY|O_CREAT|O_EXCL|_O_SHORT_LIVED, _S_IREAD|_S_IWRITE);
00143 }
00144 #endif