Fossil SCM

Add the fossil_strdup() utility function and use it instead of strdup().

drh 2011-01-26 20:38 trunk
Commit 42f6e8bed71cf395ab4de471688c5eb6e351f68d
2 files changed +3 -3 +13 -13
+3 -3
--- src/cgi.c
+++ src/cgi.c
@@ -221,11 +221,11 @@
221221
MD5Final(digest,&ctx);
222222
for(j=i=0; i<16; i++,j+=2){
223223
bprintf(&zETag[j],sizeof(zETag)-j,"%02x",(int)digest[i]);
224224
}
225225
blob_appendf(&extraHeader, "ETag: %s\r\n", zETag);
226
- return strdup(zETag);
226
+ return fossil_strdup(zETag);
227227
}
228228
229229
/*
230230
** Do some cache control stuff. First, we generate an ETag and include it in
231231
** the response headers. Second, we do whatever is necessary to determine if
@@ -241,18 +241,18 @@
241241
/* FIXME: there's some gotchas wth cookies and some headers. */
242242
char *zETag = cgi_add_etag(blob_buffer(&cgiContent),blob_size(&cgiContent));
243243
char *zMatch = P("HTTP_IF_NONE_MATCH");
244244
245245
if( zETag!=0 && zMatch!=0 ) {
246
- char *zBuf = strdup(zMatch);
246
+ char *zBuf = fossil_strdup(zMatch);
247247
if( zBuf!=0 ){
248248
char *zTok = 0;
249249
char *zPos;
250250
for( zTok = strtok_r(zBuf, ",\"",&zPos);
251251
zTok && fossil_stricmp(zTok,zETag);
252252
zTok = strtok_r(0, ",\"",&zPos)){}
253
- free(zBuf);
253
+ fossil_free(zBuf);
254254
if(zTok) return 1;
255255
}
256256
}
257257
258258
return 0;
259259
--- src/cgi.c
+++ src/cgi.c
@@ -221,11 +221,11 @@
221 MD5Final(digest,&ctx);
222 for(j=i=0; i<16; i++,j+=2){
223 bprintf(&zETag[j],sizeof(zETag)-j,"%02x",(int)digest[i]);
224 }
225 blob_appendf(&extraHeader, "ETag: %s\r\n", zETag);
226 return strdup(zETag);
227 }
228
229 /*
230 ** Do some cache control stuff. First, we generate an ETag and include it in
231 ** the response headers. Second, we do whatever is necessary to determine if
@@ -241,18 +241,18 @@
241 /* FIXME: there's some gotchas wth cookies and some headers. */
242 char *zETag = cgi_add_etag(blob_buffer(&cgiContent),blob_size(&cgiContent));
243 char *zMatch = P("HTTP_IF_NONE_MATCH");
244
245 if( zETag!=0 && zMatch!=0 ) {
246 char *zBuf = strdup(zMatch);
247 if( zBuf!=0 ){
248 char *zTok = 0;
249 char *zPos;
250 for( zTok = strtok_r(zBuf, ",\"",&zPos);
251 zTok && fossil_stricmp(zTok,zETag);
252 zTok = strtok_r(0, ",\"",&zPos)){}
253 free(zBuf);
254 if(zTok) return 1;
255 }
256 }
257
258 return 0;
259
--- src/cgi.c
+++ src/cgi.c
@@ -221,11 +221,11 @@
221 MD5Final(digest,&ctx);
222 for(j=i=0; i<16; i++,j+=2){
223 bprintf(&zETag[j],sizeof(zETag)-j,"%02x",(int)digest[i]);
224 }
225 blob_appendf(&extraHeader, "ETag: %s\r\n", zETag);
226 return fossil_strdup(zETag);
227 }
228
229 /*
230 ** Do some cache control stuff. First, we generate an ETag and include it in
231 ** the response headers. Second, we do whatever is necessary to determine if
@@ -241,18 +241,18 @@
241 /* FIXME: there's some gotchas wth cookies and some headers. */
242 char *zETag = cgi_add_etag(blob_buffer(&cgiContent),blob_size(&cgiContent));
243 char *zMatch = P("HTTP_IF_NONE_MATCH");
244
245 if( zETag!=0 && zMatch!=0 ) {
246 char *zBuf = fossil_strdup(zMatch);
247 if( zBuf!=0 ){
248 char *zTok = 0;
249 char *zPos;
250 for( zTok = strtok_r(zBuf, ",\"",&zPos);
251 zTok && fossil_stricmp(zTok,zETag);
252 zTok = strtok_r(0, ",\"",&zPos)){}
253 fossil_free(zBuf);
254 if(zTok) return 1;
255 }
256 }
257
258 return 0;
259
+13 -13
--- src/import.c
+++ src/import.c
@@ -63,11 +63,11 @@
6363
} gg;
6464
6565
/*
6666
** Duplicate a string.
6767
*/
68
-static char *import_strdup(const char *zOrig){
68
+char *fossil_strdup(const char *zOrig){
6969
char *z = 0;
7070
if( zOrig ){
7171
int n = strlen(zOrig);
7272
z = fossil_malloc( n+1 );
7373
memcpy(z, zOrig, n+1);
@@ -160,11 +160,11 @@
160160
&hash, rid, &hash
161161
);
162162
}
163163
if( saveUuid ){
164164
fossil_free(gg.zPrevCheckin);
165
- gg.zPrevCheckin = import_strdup(blob_str(&hash));
165
+ gg.zPrevCheckin = fossil_strdup(blob_str(&hash));
166166
}
167167
blob_reset(&hash);
168168
return rid;
169169
}
170170
@@ -369,13 +369,13 @@
369369
p = manifest_get(rid, CFTYPE_MANIFEST);
370370
if( p==0 ) return;
371371
manifest_file_rewind(p);
372372
while( (pOld = manifest_file_next(p, 0))!=0 ){
373373
pNew = import_add_file();
374
- pNew->zName = import_strdup(pOld->zName);
374
+ pNew->zName = fossil_strdup(pOld->zName);
375375
pNew->isExe = pOld->zPerm && strstr(pOld->zPerm, "x")!=0;
376
- pNew->zUuid = import_strdup(pOld->zUuid);
376
+ pNew->zUuid = fossil_strdup(pOld->zUuid);
377377
pNew->isFrom = 1;
378378
}
379379
manifest_destroy(p);
380380
}
381381
@@ -426,18 +426,18 @@
426426
gg.xFinish = finish_commit;
427427
trim_newline(&zLine[7]);
428428
z = &zLine[7];
429429
for(i=strlen(z)-1; i>=0 && z[i]!='/'; i--){}
430430
if( z[i+1]!=0 ) z += i+1;
431
- gg.zBranch = import_strdup(z);
431
+ gg.zBranch = fossil_strdup(z);
432432
gg.fromLoaded = 0;
433433
}else
434434
if( memcmp(zLine, "tag ", 4)==0 ){
435435
gg.xFinish();
436436
gg.xFinish = finish_tag;
437437
trim_newline(&zLine[4]);
438
- gg.zTag = import_strdup(&zLine[4]);
438
+ gg.zTag = fossil_strdup(&zLine[4]);
439439
}else
440440
if( memcmp(zLine, "reset ", 4)==0 ){
441441
gg.xFinish();
442442
}else
443443
if( memcmp(zLine, "checkpoint", 10)==0 ){
@@ -477,11 +477,11 @@
477477
/* No-op */
478478
}else
479479
if( memcmp(zLine, "mark ", 5)==0 ){
480480
trim_newline(&zLine[5]);
481481
fossil_free(gg.zMark);
482
- gg.zMark = import_strdup(&zLine[5]);
482
+ gg.zMark = fossil_strdup(&zLine[5]);
483483
}else
484484
if( memcmp(zLine, "tagger ", 7)==0 || memcmp(zLine, "committer ",10)==0 ){
485485
sqlite3_int64 secSince1970;
486486
for(i=0; zLine[i] && zLine[i]!='<'; i++){}
487487
if( zLine[i]==0 ) goto malformed_line;
@@ -488,11 +488,11 @@
488488
z = &zLine[i+1];
489489
for(i=i+1; zLine[i] && zLine[i]!='>'; i++){}
490490
if( zLine[i]==0 ) goto malformed_line;
491491
zLine[i] = 0;
492492
fossil_free(gg.zUser);
493
- gg.zUser = import_strdup(z);
493
+ gg.zUser = fossil_strdup(z);
494494
secSince1970 = 0;
495495
for(i=i+2; fossil_isdigit(zLine[i]); i++){
496496
secSince1970 = secSince1970*10 + zLine[i] - '0';
497497
}
498498
fossil_free(gg.zDate);
@@ -500,11 +500,11 @@
500500
gg.zDate[10] = 'T';
501501
}else
502502
if( memcmp(zLine, "from ", 5)==0 ){
503503
trim_newline(&zLine[5]);
504504
fossil_free(gg.zFromMark);
505
- gg.zFromMark = import_strdup(&zLine[5]);
505
+ gg.zFromMark = fossil_strdup(&zLine[5]);
506506
fossil_free(gg.zFrom);
507507
gg.zFrom = resolve_committish(&zLine[5]);
508508
}else
509509
if( memcmp(zLine, "merge ", 6)==0 ){
510510
trim_newline(&zLine[6]);
@@ -523,11 +523,11 @@
523523
zName = rest_of_line(&z);
524524
i = 0;
525525
pFile = import_find_file(zName, &i, gg.nFile);
526526
if( pFile==0 ){
527527
pFile = import_add_file();
528
- pFile->zName = import_strdup(zName);
528
+ pFile->zName = fossil_strdup(zName);
529529
}
530530
pFile->isExe = (fossil_strcmp(zPerm, "100755")==0);
531531
fossil_free(pFile->zUuid);
532532
pFile->zUuid = resolve_committish(zUuid);
533533
pFile->isFrom = 0;
@@ -560,14 +560,14 @@
560560
pNew = import_add_file();
561561
pFile = &gg.aFile[i-1];
562562
if( strlen(pFile->zName)>nFrom ){
563563
pNew->zName = mprintf("%s%s", zTo, pFile->zName[nFrom]);
564564
}else{
565
- pNew->zName = import_strdup(pFile->zName);
565
+ pNew->zName = fossil_strdup(pFile->zName);
566566
}
567567
pNew->isExe = pFile->isExe;
568
- pNew->zUuid = import_strdup(pFile->zUuid);
568
+ pNew->zUuid = fossil_strdup(pFile->zUuid);
569569
pNew->isFrom = 0;
570570
}
571571
}else
572572
if( memcmp(zLine, "R ", 2)==0 ){
573573
int nFrom;
@@ -582,11 +582,11 @@
582582
pNew = import_add_file();
583583
pFile = &gg.aFile[i-1];
584584
if( strlen(pFile->zName)>nFrom ){
585585
pNew->zName = mprintf("%s%s", zTo, pFile->zName[nFrom]);
586586
}else{
587
- pNew->zName = import_strdup(pFile->zName);
587
+ pNew->zName = fossil_strdup(pFile->zName);
588588
}
589589
pNew->zPrior = pFile->zName;
590590
pNew->isExe = pFile->isExe;
591591
pNew->zUuid = pFile->zUuid;
592592
pNew->isFrom = 0;
593593
--- src/import.c
+++ src/import.c
@@ -63,11 +63,11 @@
63 } gg;
64
65 /*
66 ** Duplicate a string.
67 */
68 static char *import_strdup(const char *zOrig){
69 char *z = 0;
70 if( zOrig ){
71 int n = strlen(zOrig);
72 z = fossil_malloc( n+1 );
73 memcpy(z, zOrig, n+1);
@@ -160,11 +160,11 @@
160 &hash, rid, &hash
161 );
162 }
163 if( saveUuid ){
164 fossil_free(gg.zPrevCheckin);
165 gg.zPrevCheckin = import_strdup(blob_str(&hash));
166 }
167 blob_reset(&hash);
168 return rid;
169 }
170
@@ -369,13 +369,13 @@
369 p = manifest_get(rid, CFTYPE_MANIFEST);
370 if( p==0 ) return;
371 manifest_file_rewind(p);
372 while( (pOld = manifest_file_next(p, 0))!=0 ){
373 pNew = import_add_file();
374 pNew->zName = import_strdup(pOld->zName);
375 pNew->isExe = pOld->zPerm && strstr(pOld->zPerm, "x")!=0;
376 pNew->zUuid = import_strdup(pOld->zUuid);
377 pNew->isFrom = 1;
378 }
379 manifest_destroy(p);
380 }
381
@@ -426,18 +426,18 @@
426 gg.xFinish = finish_commit;
427 trim_newline(&zLine[7]);
428 z = &zLine[7];
429 for(i=strlen(z)-1; i>=0 && z[i]!='/'; i--){}
430 if( z[i+1]!=0 ) z += i+1;
431 gg.zBranch = import_strdup(z);
432 gg.fromLoaded = 0;
433 }else
434 if( memcmp(zLine, "tag ", 4)==0 ){
435 gg.xFinish();
436 gg.xFinish = finish_tag;
437 trim_newline(&zLine[4]);
438 gg.zTag = import_strdup(&zLine[4]);
439 }else
440 if( memcmp(zLine, "reset ", 4)==0 ){
441 gg.xFinish();
442 }else
443 if( memcmp(zLine, "checkpoint", 10)==0 ){
@@ -477,11 +477,11 @@
477 /* No-op */
478 }else
479 if( memcmp(zLine, "mark ", 5)==0 ){
480 trim_newline(&zLine[5]);
481 fossil_free(gg.zMark);
482 gg.zMark = import_strdup(&zLine[5]);
483 }else
484 if( memcmp(zLine, "tagger ", 7)==0 || memcmp(zLine, "committer ",10)==0 ){
485 sqlite3_int64 secSince1970;
486 for(i=0; zLine[i] && zLine[i]!='<'; i++){}
487 if( zLine[i]==0 ) goto malformed_line;
@@ -488,11 +488,11 @@
488 z = &zLine[i+1];
489 for(i=i+1; zLine[i] && zLine[i]!='>'; i++){}
490 if( zLine[i]==0 ) goto malformed_line;
491 zLine[i] = 0;
492 fossil_free(gg.zUser);
493 gg.zUser = import_strdup(z);
494 secSince1970 = 0;
495 for(i=i+2; fossil_isdigit(zLine[i]); i++){
496 secSince1970 = secSince1970*10 + zLine[i] - '0';
497 }
498 fossil_free(gg.zDate);
@@ -500,11 +500,11 @@
500 gg.zDate[10] = 'T';
501 }else
502 if( memcmp(zLine, "from ", 5)==0 ){
503 trim_newline(&zLine[5]);
504 fossil_free(gg.zFromMark);
505 gg.zFromMark = import_strdup(&zLine[5]);
506 fossil_free(gg.zFrom);
507 gg.zFrom = resolve_committish(&zLine[5]);
508 }else
509 if( memcmp(zLine, "merge ", 6)==0 ){
510 trim_newline(&zLine[6]);
@@ -523,11 +523,11 @@
523 zName = rest_of_line(&z);
524 i = 0;
525 pFile = import_find_file(zName, &i, gg.nFile);
526 if( pFile==0 ){
527 pFile = import_add_file();
528 pFile->zName = import_strdup(zName);
529 }
530 pFile->isExe = (fossil_strcmp(zPerm, "100755")==0);
531 fossil_free(pFile->zUuid);
532 pFile->zUuid = resolve_committish(zUuid);
533 pFile->isFrom = 0;
@@ -560,14 +560,14 @@
560 pNew = import_add_file();
561 pFile = &gg.aFile[i-1];
562 if( strlen(pFile->zName)>nFrom ){
563 pNew->zName = mprintf("%s%s", zTo, pFile->zName[nFrom]);
564 }else{
565 pNew->zName = import_strdup(pFile->zName);
566 }
567 pNew->isExe = pFile->isExe;
568 pNew->zUuid = import_strdup(pFile->zUuid);
569 pNew->isFrom = 0;
570 }
571 }else
572 if( memcmp(zLine, "R ", 2)==0 ){
573 int nFrom;
@@ -582,11 +582,11 @@
582 pNew = import_add_file();
583 pFile = &gg.aFile[i-1];
584 if( strlen(pFile->zName)>nFrom ){
585 pNew->zName = mprintf("%s%s", zTo, pFile->zName[nFrom]);
586 }else{
587 pNew->zName = import_strdup(pFile->zName);
588 }
589 pNew->zPrior = pFile->zName;
590 pNew->isExe = pFile->isExe;
591 pNew->zUuid = pFile->zUuid;
592 pNew->isFrom = 0;
593
--- src/import.c
+++ src/import.c
@@ -63,11 +63,11 @@
63 } gg;
64
65 /*
66 ** Duplicate a string.
67 */
68 char *fossil_strdup(const char *zOrig){
69 char *z = 0;
70 if( zOrig ){
71 int n = strlen(zOrig);
72 z = fossil_malloc( n+1 );
73 memcpy(z, zOrig, n+1);
@@ -160,11 +160,11 @@
160 &hash, rid, &hash
161 );
162 }
163 if( saveUuid ){
164 fossil_free(gg.zPrevCheckin);
165 gg.zPrevCheckin = fossil_strdup(blob_str(&hash));
166 }
167 blob_reset(&hash);
168 return rid;
169 }
170
@@ -369,13 +369,13 @@
369 p = manifest_get(rid, CFTYPE_MANIFEST);
370 if( p==0 ) return;
371 manifest_file_rewind(p);
372 while( (pOld = manifest_file_next(p, 0))!=0 ){
373 pNew = import_add_file();
374 pNew->zName = fossil_strdup(pOld->zName);
375 pNew->isExe = pOld->zPerm && strstr(pOld->zPerm, "x")!=0;
376 pNew->zUuid = fossil_strdup(pOld->zUuid);
377 pNew->isFrom = 1;
378 }
379 manifest_destroy(p);
380 }
381
@@ -426,18 +426,18 @@
426 gg.xFinish = finish_commit;
427 trim_newline(&zLine[7]);
428 z = &zLine[7];
429 for(i=strlen(z)-1; i>=0 && z[i]!='/'; i--){}
430 if( z[i+1]!=0 ) z += i+1;
431 gg.zBranch = fossil_strdup(z);
432 gg.fromLoaded = 0;
433 }else
434 if( memcmp(zLine, "tag ", 4)==0 ){
435 gg.xFinish();
436 gg.xFinish = finish_tag;
437 trim_newline(&zLine[4]);
438 gg.zTag = fossil_strdup(&zLine[4]);
439 }else
440 if( memcmp(zLine, "reset ", 4)==0 ){
441 gg.xFinish();
442 }else
443 if( memcmp(zLine, "checkpoint", 10)==0 ){
@@ -477,11 +477,11 @@
477 /* No-op */
478 }else
479 if( memcmp(zLine, "mark ", 5)==0 ){
480 trim_newline(&zLine[5]);
481 fossil_free(gg.zMark);
482 gg.zMark = fossil_strdup(&zLine[5]);
483 }else
484 if( memcmp(zLine, "tagger ", 7)==0 || memcmp(zLine, "committer ",10)==0 ){
485 sqlite3_int64 secSince1970;
486 for(i=0; zLine[i] && zLine[i]!='<'; i++){}
487 if( zLine[i]==0 ) goto malformed_line;
@@ -488,11 +488,11 @@
488 z = &zLine[i+1];
489 for(i=i+1; zLine[i] && zLine[i]!='>'; i++){}
490 if( zLine[i]==0 ) goto malformed_line;
491 zLine[i] = 0;
492 fossil_free(gg.zUser);
493 gg.zUser = fossil_strdup(z);
494 secSince1970 = 0;
495 for(i=i+2; fossil_isdigit(zLine[i]); i++){
496 secSince1970 = secSince1970*10 + zLine[i] - '0';
497 }
498 fossil_free(gg.zDate);
@@ -500,11 +500,11 @@
500 gg.zDate[10] = 'T';
501 }else
502 if( memcmp(zLine, "from ", 5)==0 ){
503 trim_newline(&zLine[5]);
504 fossil_free(gg.zFromMark);
505 gg.zFromMark = fossil_strdup(&zLine[5]);
506 fossil_free(gg.zFrom);
507 gg.zFrom = resolve_committish(&zLine[5]);
508 }else
509 if( memcmp(zLine, "merge ", 6)==0 ){
510 trim_newline(&zLine[6]);
@@ -523,11 +523,11 @@
523 zName = rest_of_line(&z);
524 i = 0;
525 pFile = import_find_file(zName, &i, gg.nFile);
526 if( pFile==0 ){
527 pFile = import_add_file();
528 pFile->zName = fossil_strdup(zName);
529 }
530 pFile->isExe = (fossil_strcmp(zPerm, "100755")==0);
531 fossil_free(pFile->zUuid);
532 pFile->zUuid = resolve_committish(zUuid);
533 pFile->isFrom = 0;
@@ -560,14 +560,14 @@
560 pNew = import_add_file();
561 pFile = &gg.aFile[i-1];
562 if( strlen(pFile->zName)>nFrom ){
563 pNew->zName = mprintf("%s%s", zTo, pFile->zName[nFrom]);
564 }else{
565 pNew->zName = fossil_strdup(pFile->zName);
566 }
567 pNew->isExe = pFile->isExe;
568 pNew->zUuid = fossil_strdup(pFile->zUuid);
569 pNew->isFrom = 0;
570 }
571 }else
572 if( memcmp(zLine, "R ", 2)==0 ){
573 int nFrom;
@@ -582,11 +582,11 @@
582 pNew = import_add_file();
583 pFile = &gg.aFile[i-1];
584 if( strlen(pFile->zName)>nFrom ){
585 pNew->zName = mprintf("%s%s", zTo, pFile->zName[nFrom]);
586 }else{
587 pNew->zName = fossil_strdup(pFile->zName);
588 }
589 pNew->zPrior = pFile->zName;
590 pNew->isExe = pFile->isExe;
591 pNew->zUuid = pFile->zUuid;
592 pNew->isFrom = 0;
593

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button