Switch to unified view

a/src/pathut.cpp b/src/pathut.cpp
...
...
22
#endif
22
#endif
23
23
24
#include <stdio.h>
24
#include <stdio.h>
25
#include <math.h>
25
#include <math.h>
26
#include <errno.h>
26
#include <errno.h>
27
28
#ifdef _WIN32
29
#include "dirent.h"
27
#include <dirent.h>
28
29
#ifdef _WIN32
30
#include "safefcntl.h"
30
#include "safefcntl.h"
31
#include "safeunistd.h"
31
#include "safeunistd.h"
32
#include "safewindows.h"
32
#include "safewindows.h"
33
#include "safesysstat.h"
33
#include "safesysstat.h"
34
#include "transcode.h"
35
36
#define STAT _wstat
37
#define LSTAT _wstat
38
#define STATBUF _stat
39
#define ACCESS _waccess
34
40
35
#else // Not windows ->
41
#else // Not windows ->
36
#include <fcntl.h>
42
#include <fcntl.h>
37
#include <unistd.h>
43
#include <unistd.h>
38
#include <sys/param.h>
44
#include <sys/param.h>
39
#include <pwd.h>
45
#include <pwd.h>
40
#include <sys/file.h>
46
#include <sys/file.h>
41
#include <sys/stat.h>
47
#include <sys/stat.h>
42
#include <dirent.h>
43
#include <sys/statvfs.h>
48
#include <sys/statvfs.h>
44
#include <sys/types.h>
49
#include <sys/types.h>
45
50
51
#define STAT stat
52
#define LSTAT lstat
53
#define STATBUF stat
54
#define ACCESS access
46
#endif
55
#endif
47
56
48
#include <cstdlib>
57
#include <cstdlib>
49
#include <cstring>
58
#include <cstring>
50
#include <iostream>
59
#include <iostream>
...
...
504
    return true;
513
    return true;
505
}
514
}
506
515
507
bool path_isdir(const string& path)
516
bool path_isdir(const string& path)
508
{
517
{
509
    struct stat st;
518
    struct STATBUF st;
510
    if (lstat(path.c_str(), &st) < 0) {
519
    SYSPATH(path, syspath);
520
    if (LSTAT(syspath, &st) < 0) {
511
        return false;
521
        return false;
512
    }
522
    }
513
    if (S_ISDIR(st.st_mode)) {
523
    if (S_ISDIR(st.st_mode)) {
514
        return true;
524
        return true;
515
    }
525
    }
516
    return false;
526
    return false;
517
}
527
}
518
528
519
long long path_filesize(const string& path)
529
long long path_filesize(const string& path)
520
{
530
{
521
    struct stat st;
531
    struct STATBUF st;
522
    if (stat(path.c_str(), &st) < 0) {
532
    SYSPATH(path, syspath);
533
    if (STAT(syspath, &st) < 0) {
523
        return -1;
534
        return -1;
524
    }
535
    }
525
    return (long long)st.st_size;
536
    return (long long)st.st_size;
526
}
537
}
527
538
...
...
529
{
540
{
530
    if (!stp) {
541
    if (!stp) {
531
        return -1;
542
        return -1;
532
    }
543
    }
533
    memset(stp, 0, sizeof(struct stat));
544
    memset(stp, 0, sizeof(struct stat));
534
    struct stat mst;
545
    struct STATBUF mst;
535
    int ret = follow ? stat(path.c_str(), &mst) : lstat(path.c_str(), &mst);
546
    SYSPATH(path, syspath);
547
    int ret = follow ? STAT(syspath, &mst) : LSTAT(syspath, &mst);
536
    if (ret != 0) {
548
    if (ret != 0) {
537
        return ret;
549
        return ret;
538
    }
550
    }
539
    stp->st_size = mst.st_size;
551
    stp->st_size = mst.st_size;
540
    stp->st_mode = mst.st_mode;
552
    stp->st_mode = mst.st_mode;
...
...
549
    return 0;
561
    return 0;
550
}
562
}
551
563
552
bool path_exists(const string& path)
564
bool path_exists(const string& path)
553
{
565
{
554
    return access(path.c_str(), 0) == 0;
566
    SYSPATH(path, syspath);
567
    return ACCESS(syspath, 0) == 0;
568
}
569
bool path_readable(const string& path)
570
{
571
    SYSPATH(path, syspath);
572
    return ACCESS(syspath, R_OK) == 0;
555
}
573
}
556
574
557
// Allowed punctuation in the path part of an URI according to RFC2396
575
// Allowed punctuation in the path part of an URI according to RFC2396
558
// -_.!~*'():@&=+$,
576
// -_.!~*'():@&=+$,
559
/*
577
/*