435
436
437
438
439
440
441
442
443
444
445
446
447
448
|
const char *zTail = file_tail(z);
if( zTail && zTail!=z ){
return mprintf("%.*s", (int)(zTail-z-1), z);
}else{
return 0;
}
}
/*
** Rename a file or directory.
** Returns zero upon success.
*/
int file_rename(
const char *zFrom,
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
|
const char *zTail = file_tail(z);
if( zTail && zTail!=z ){
return mprintf("%.*s", (int)(zTail-z-1), z);
}else{
return 0;
}
}
/* SQL Function: file_dirname(NAME)
**
** Return the directory for NAME
*/
void file_dirname_sql_function(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
const char *zName = (const char*)sqlite3_value_text(argv[0]);
char *zDir;
if( zName==0 ) return;
zDir = file_dirname(zName);
if( zDir ){
sqlite3_result_text(context,zDir,-1,fossil_free);
}
}
/*
** Rename a file or directory.
** Returns zero upon success.
*/
int file_rename(
const char *zFrom,
|
592
593
594
595
596
597
598
599
600
601
602
603
604
605
|
#else
char *z = fossil_utf8_to_path(zFilename, 0);
rc = unlink(zFilename);
#endif
fossil_path_free(z);
return rc;
}
/*
** Create a directory called zName, if it does not already exist.
** If forceFlag is 1, delete any prior non-directory object
** with the same name.
**
** Return the number of errors.
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
|
#else
char *z = fossil_utf8_to_path(zFilename, 0);
rc = unlink(zFilename);
#endif
fossil_path_free(z);
return rc;
}
/* SQL Function: file_delete(NAME)
**
** Remove file NAME. Return zero on success and non-zero if anything goes
** wrong.
*/
void file_delete_sql_function(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
const char *zName = (const char*)sqlite3_value_text(argv[0]);
int rc;
if( zName==0 ){
rc = 1;
}else{
rc = file_delete(zName);
}
sqlite3_result_int(context, rc);
}
/*
** Create a directory called zName, if it does not already exist.
** If forceFlag is 1, delete any prior non-directory object
** with the same name.
**
** Return the number of errors.
|
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
|
/*
** Get the current working directory.
**
** On windows, the name is converted from unicode to UTF8 and all '\\'
** characters are converted to '/'. No conversions are needed on
** unix.
*/
void file_getcwd(char *zBuf, int nBuf){
#ifdef _WIN32
win32_getcwd(zBuf, nBuf);
#else
if( getcwd(zBuf, nBuf-1)==0 ){
if( errno==ERANGE ){
fossil_panic("pwd too big: max %d", nBuf-1);
}else{
fossil_panic("cannot find current working directory; %s",
strerror(errno));
}
}
#endif
}
/*
** Return true if zPath is an absolute pathname. Return false
** if it is relative.
*/
int file_is_absolute_path(const char *zPath){
|
>
>
>
|
>
>
>
>
>
>
|
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
|
/*
** Get the current working directory.
**
** On windows, the name is converted from unicode to UTF8 and all '\\'
** characters are converted to '/'. No conversions are needed on
** unix.
**
** Store the value of the CWD in zBuf which is nBuf bytes in size.
** or if zBuf==0, allocate space to hold the result using fossil_malloc().
*/
char *file_getcwd(char *zBuf, int nBuf){
char zTemp[2000];
if( zBuf==0 ){
zBuf = zTemp;
nBuf = sizeof(zTemp);
}
#ifdef _WIN32
win32_getcwd(zBuf, nBuf);
#else
if( getcwd(zBuf, nBuf-1)==0 ){
if( errno==ERANGE ){
fossil_panic("pwd too big: max %d", nBuf-1);
}else{
fossil_panic("cannot find current working directory; %s",
strerror(errno));
}
}
#endif
return zBuf==zTemp ? fossil_strdup(zBuf) : zBuf;
}
/*
** Return true if zPath is an absolute pathname. Return false
** if it is relative.
*/
int file_is_absolute_path(const char *zPath){
|