aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c152
1 files changed, 0 insertions, 152 deletions
diff --git a/src/utils.c b/src/utils.c
deleted file mode 100644
index 3552189c..00000000
--- a/src/utils.c
+++ /dev/null
@@ -1,152 +0,0 @@
1/* Copyrights 2002 Luis Figueiredo (stdio@netc.pt) All rights reserved.
2 *
3 * See the LICENSE file
4 *
5 * The origin of this software must not be misrepresented, either by
6 * explicit claim or by omission. Since few users ever read sources,
7 * credits must appear in the documentation.
8 *
9 * date: 19:49,07-49-2002
10 *
11 * -- description: utilitys
12 *
13 */
14
15#include "utils.h"
16
17/*********************************************************************************************************/
18/*
19 * search a string in a string ignoring case
20 */
21char *__ILWS_stristr(char *str, const char *nedle) {
22 char *tmp1=str;
23 int ret=1;
24 int snedle=strlen(nedle),sstr=strlen(str);
25 if(strlen(str)<strlen(nedle))return NULL;
26 while((ret=strncasecmp(tmp1,nedle,snedle) && (unsigned int)(tmp1+snedle)<=(unsigned int) (str+sstr))) {
27 tmp1++;
28 };
29 if(strncasecmp(tmp1,nedle,snedle))
30 return NULL;
31 return tmp1;
32};
33
34/*********************************************************************************************************/
35/*
36 * gives a new temporary path(file) name that doesn't exists
37 */
38char *_tmpnameprefix="";
39
40char *__ILWS_tmpfname() {
41 char *ret=NULL;
42 char *tmpdir=NULL;
43 char nam[TMPNAMESIZE+1];
44 int i;
45 struct stat foostat;
46 if(tmpdir==NULL) {
47 tmpdir=getenv("TEMP");
48 };
49 if(tmpdir==NULL) {
50 tmpdir=getenv("TMP");
51 };
52 if(tmpdir==NULL) {
53 tmpdir=getenv("TMPDIR");
54 };
55 if(tmpdir==NULL) {
56 tmpdir=P_tmpdir; // defined in stdio.h
57 };
58 if(!(ret=__ILWS_malloc(strlen(tmpdir)+strlen(_tmpnameprefix)+TMPNAMESIZE+2))) {
59 return NULL;
60 };
61 srand(time(NULL)); // seed
62 do {
63 for(i=0;i<TMPNAMESIZE;i++) {
64
65 nam[i]=(rand()%2)?(rand()%26)+'A':(rand()%26)+'a';
66 }
67 nam[i]=0;
68 snprintf(ret,strlen(tmpdir)+strlen(_tmpnameprefix)+TMPNAMESIZE+2,"%s/%s%s",tmpdir,_tmpnameprefix,nam); // include '0'
69 }while((stat(ret,&foostat)!=-1) && (lstat(ret,&foostat)!=-1)); // redundancy if win32 // <- race condition?
70 return ret;
71};
72
73
74
75/*********************************************************************************************************/
76/*
77 * an date function
78 */
79#define DATE_MAX 100
80char __ILWS_datem[DATE_MAX];
81
82char *__ILWS_date(time_t t,const char *format) {
83 struct tm *tm;
84 tm=localtime(&t);
85 strftime(__ILWS_datem,DATE_MAX,format,tm);
86 return __ILWS_datem;
87}
88
89/*********************************************************************************************************/
90/*
91 * wasn't me, base64decode
92 */
93static const unsigned char __ILWS_chtb[256] = {
94 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
95 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
96 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
97 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
98 64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
99 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
100 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
101 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
102 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
103 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
104 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
105 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
106 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
107 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
108 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
109 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64};
110
111
112int __ILWS_base64decode(char *bufplain, const char *bufcoded){
113 int nb;
114 const unsigned char *in;
115 unsigned char *out;
116 int nprbytes;
117
118 in = (const unsigned char *) bufcoded;
119 while (__ILWS_chtb[*(in++)] <= 63);
120 nprbytes = (in - (const unsigned char *) bufcoded) - 1;
121 nb = ((nprbytes + 3) / 4) * 3;
122
123 out = (unsigned char *) bufplain;
124 in = (const unsigned char *) bufcoded;
125
126 while (nprbytes > 4) {
127 *(out++) =
128 (unsigned char) (__ILWS_chtb[*in] << 2 | __ILWS_chtb[in[1]] >> 4);
129 *(out++) =
130 (unsigned char) (__ILWS_chtb[in[1]] << 4 | __ILWS_chtb[in[2]] >> 2);
131 *(out++) =
132 (unsigned char) (__ILWS_chtb[in[2]] << 6 | __ILWS_chtb[in[3]]);
133 in += 4;
134 nprbytes -= 4;
135 }
136 if (nprbytes > 1) {
137 *(out++) =
138 (unsigned char) (__ILWS_chtb[*in] << 2 | __ILWS_chtb[in[1]] >> 4);
139 }
140 if (nprbytes > 2) {
141 *(out++) =
142 (unsigned char) (__ILWS_chtb[in[1]] << 4 | __ILWS_chtb[in[2]] >> 2);
143 }
144 if (nprbytes > 3) {
145 *(out++) =
146 (unsigned char) (__ILWS_chtb[in[2]] << 6 | __ILWS_chtb[in[3]]);
147 }
148
149 nb -= (4 - nprbytes) & 3;
150 return nb;
151}
152