File: filefoun.c

package info (click to toggle)
icmake 6.22-7
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,148 kB
  • ctags: 1,042
  • sloc: ansic: 9,241; makefile: 1,134; sh: 235; asm: 126
file content (78 lines) | stat: -rw-r--r-- 2,425 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
                            F I L E F O U N . C

    With the MS-DOS implementation the received attribute is compared
    to the request:

    O_FILE:     accepts only A_NORMAL, A_ARCH/A_READ with A_NORMAL accepted
    O_DIR:      accepts only A_SUBDIR
    O_SUBDIR:   accepts only A_SUBDIR, but not the . and ..
    O_ALL:      accepts all

    Not yet supported: O_VOLID:    accepts A_VOLID

*/

#include "icrssdef.h"

char *filefound()
{
    register unsigned
        request,
        received;

    received = ifs.find.attrib;             /* use fast registers */
    request = ifs.attrib;

    /* First part: see if request */
    /* matches attribute of entry */

    if                                      /* (list all accepted variants) */
    (
        !                                   /* if not: */
        (
            (
             (request & O_FILE)             /* FILE requested, and */
             &&                             /* an attribute received  */
             !                              /* indicating that it's no file */
             (
                 received &
                 (A_SUBDIR | A_HIDDEN | A_SYSTEM | A_VOLID)
             )
            )
            ||
            (
             (request & (O_SUBDIR | O_DIR)) /* OR: any subdir requested */
             &&                             /* and A_SUBDIR received */
             (received & A_SUBDIR)
            )
            ||
            (
             (request & O_ALL)              /* OR: ALL requested */
             &&                             /* and not volume label received */
             !(received & A_VOLID)
            )
        )
    )
        return (NULL);                      /* then reject the entry */


    /* Second part: O_SUBDIR (overruled by O_ALL / O_DIR)   */
    /*              entries '.' and '..' are rejected       */

    if
    (
        !(request & (O_DIR | O_ALL))        /* not O_DIR / O_ALL requested, */
        &&                                  /* AND */
        (request & O_SUBDIR)                /* clean subdir requested */
        &&                                  /* AND */
        (
            !strcmp(ifs.find.name, ".")     /* . or .. found */
            ||
            !strcmp(ifs.find.name, "..")
        )
    )
        return (NULL);                      /* then reject the entry */

    return (ifs.find.name);                 /* return found name */
}