VirtualBox

Changeset 3138 in kBuild for vendor/gnumake/current/w32/compat


Ignore:
Timestamp:
Mar 12, 2018 7:32:29 PM (7 years ago)
Author:
bird
Message:

Imported make 4.2.1 (2e55f5e4abdc0e38c1d64be703b446695e70b3b6) from https://git.savannah.gnu.org/git/make.git.

Location:
vendor/gnumake/current/w32/compat
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/gnumake/current/w32/compat/dirent.c

    r2596 r3138  
    11/* Directory entry code for Window platforms.
    2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
    3 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
     2Copyright (C) 1996-2016 Free Software Foundation, Inc.
    43This file is part of GNU Make.
    54
     
    2928opendir(const char* pDirName)
    3029{
    31         struct stat sb;
    32         DIR*    pDir;
    33         char*   pEndDirName;
    34         int     nBufferLen;
    35 
    36         /* sanity checks */
    37         if (!pDirName) {
    38                 errno = EINVAL;
    39                 return NULL;
    40         }
    41         if (stat(pDirName, &sb) != 0) {
    42                 errno = ENOENT;
    43                 return NULL;
    44         }
    45         if ((sb.st_mode & S_IFMT) != S_IFDIR) {
    46                 errno = ENOTDIR;
    47                 return NULL;
    48         }
    49 
    50         /* allocate a DIR structure to return */
    51         pDir = (DIR *) malloc(sizeof (DIR));
    52 
    53         if (!pDir)
    54                 return NULL;
    55 
    56         /* input directory name length */
    57         nBufferLen = strlen(pDirName);
    58 
    59         /* copy input directory name to DIR buffer */
    60         strcpy(pDir->dir_pDirectoryName, pDirName);
    61 
    62         /* point to end of the copied directory name */
    63         pEndDirName = &pDir->dir_pDirectoryName[nBufferLen - 1];
    64 
    65         /* if directory name did not end in '/' or '\', add '/' */
    66         if ((*pEndDirName != '/') && (*pEndDirName != '\\')) {
    67                 pEndDirName++;
    68                 *pEndDirName = '/';
    69         }
    70 
    71         /* now append the wildcard character to the buffer */
    72         pEndDirName++;
    73         *pEndDirName = '*';
    74         pEndDirName++;
    75         *pEndDirName = '\0';
    76 
    77         /* other values defaulted */
    78         pDir->dir_nNumFiles = 0;
    79         pDir->dir_hDirHandle = INVALID_HANDLE_VALUE;
    80         pDir->dir_ulCookie = __DIRENT_COOKIE;
    81 
    82         return pDir;
     30        struct stat sb;
     31        DIR*    pDir;
     32        char*   pEndDirName;
     33        int     nBufferLen;
     34
     35        /* sanity checks */
     36        if (!pDirName) {
     37                errno = EINVAL;
     38                return NULL;
     39        }
     40        if (stat(pDirName, &sb) != 0) {
     41                errno = ENOENT;
     42                return NULL;
     43        }
     44        if ((sb.st_mode & S_IFMT) != S_IFDIR) {
     45                errno = ENOTDIR;
     46                return NULL;
     47        }
     48
     49        /* allocate a DIR structure to return */
     50        pDir = (DIR *) malloc(sizeof (DIR));
     51
     52        if (!pDir)
     53                return NULL;
     54
     55        /* input directory name length */
     56        nBufferLen = strlen(pDirName);
     57
     58        /* copy input directory name to DIR buffer */
     59        strcpy(pDir->dir_pDirectoryName, pDirName);
     60
     61        /* point to end of the copied directory name */
     62        pEndDirName = &pDir->dir_pDirectoryName[nBufferLen - 1];
     63
     64        /* if directory name did not end in '/' or '\', add '/' */
     65        if ((*pEndDirName != '/') && (*pEndDirName != '\\')) {
     66                pEndDirName++;
     67                *pEndDirName = '/';
     68        }
     69
     70        /* now append the wildcard character to the buffer */
     71        pEndDirName++;
     72        *pEndDirName = '*';
     73        pEndDirName++;
     74        *pEndDirName = '\0';
     75
     76        /* other values defaulted */
     77        pDir->dir_nNumFiles = 0;
     78        pDir->dir_hDirHandle = INVALID_HANDLE_VALUE;
     79        pDir->dir_ulCookie = __DIRENT_COOKIE;
     80
     81        return pDir;
    8382}
    8483
     
    8685closedir(DIR *pDir)
    8786{
    88         /* got a valid pointer? */
    89         if (!pDir) {
    90                 errno = EINVAL;
    91                 return;
    92         }
    93 
    94         /* sanity check that this is a DIR pointer */
    95         if (pDir->dir_ulCookie != __DIRENT_COOKIE) {
    96                 errno = EINVAL;
    97                 return;
    98         }
    99 
    100         /* close the WINDOWS32 directory handle */
    101         if (pDir->dir_hDirHandle != INVALID_HANDLE_VALUE)
    102                 FindClose(pDir->dir_hDirHandle);
    103 
    104         free(pDir);
    105 
    106         return;
     87        /* got a valid pointer? */
     88        if (!pDir) {
     89                errno = EINVAL;
     90                return;
     91        }
     92
     93        /* sanity check that this is a DIR pointer */
     94        if (pDir->dir_ulCookie != __DIRENT_COOKIE) {
     95                errno = EINVAL;
     96                return;
     97        }
     98
     99        /* close the WINDOWS32 directory handle */
     100        if (pDir->dir_hDirHandle != INVALID_HANDLE_VALUE)
     101                FindClose(pDir->dir_hDirHandle);
     102
     103        free(pDir);
     104
     105        return;
    107106}
    108107
     
    110109readdir(DIR* pDir)
    111110{
    112         WIN32_FIND_DATA wfdFindData;
    113 
    114         if (!pDir) {
    115                 errno = EINVAL;
    116                 return NULL;
    117         }
    118 
    119         /* sanity check that this is a DIR pointer */
    120         if (pDir->dir_ulCookie != __DIRENT_COOKIE) {
    121                 errno = EINVAL;
    122                 return NULL;
    123         }
    124 
    125         if (pDir->dir_nNumFiles == 0) {
    126                 pDir->dir_hDirHandle = FindFirstFile(pDir->dir_pDirectoryName, &wfdFindData);
    127                 if (pDir->dir_hDirHandle == INVALID_HANDLE_VALUE)
    128                         return NULL;
    129         } else if (!FindNextFile(pDir->dir_hDirHandle, &wfdFindData))
    130                         return NULL;
    131 
    132         /* bump count for next call to readdir() or telldir() */
    133         pDir->dir_nNumFiles++;
    134 
    135         /* fill in struct dirent values */
    136         pDir->dir_sdReturn.d_ino = (ino_t)-1;
    137         strcpy(pDir->dir_sdReturn.d_name, wfdFindData.cFileName);
    138 
    139         return &pDir->dir_sdReturn;
     111        WIN32_FIND_DATA wfdFindData;
     112
     113        if (!pDir) {
     114                errno = EINVAL;
     115                return NULL;
     116        }
     117
     118        /* sanity check that this is a DIR pointer */
     119        if (pDir->dir_ulCookie != __DIRENT_COOKIE) {
     120                errno = EINVAL;
     121                return NULL;
     122        }
     123
     124        if (pDir->dir_nNumFiles == 0) {
     125                pDir->dir_hDirHandle = FindFirstFile(pDir->dir_pDirectoryName, &wfdFindData);
     126                if (pDir->dir_hDirHandle == INVALID_HANDLE_VALUE)
     127                        return NULL;
     128        } else if (!FindNextFile(pDir->dir_hDirHandle, &wfdFindData))
     129                        return NULL;
     130
     131        /* bump count for next call to readdir() or telldir() */
     132        pDir->dir_nNumFiles++;
     133
     134        /* fill in struct dirent values */
     135        pDir->dir_sdReturn.d_ino = (ino_t)-1;
     136        strcpy(pDir->dir_sdReturn.d_name, wfdFindData.cFileName);
     137
     138        return &pDir->dir_sdReturn;
    140139}
    141140
     
    143142rewinddir(DIR* pDir)
    144143{
    145         if (!pDir) {
    146                 errno = EINVAL;
    147                 return;
    148         }
    149 
    150         /* sanity check that this is a DIR pointer */
    151         if (pDir->dir_ulCookie != __DIRENT_COOKIE) {
    152                 errno = EINVAL;
    153                 return;
    154         }
    155 
    156         /* close the WINDOWS32 directory handle */
    157         if (pDir->dir_hDirHandle != INVALID_HANDLE_VALUE)
    158                 if (!FindClose(pDir->dir_hDirHandle))
    159                         errno = EBADF;
    160 
    161         /* reset members which control readdir() */
    162         pDir->dir_hDirHandle = INVALID_HANDLE_VALUE;
    163         pDir->dir_nNumFiles = 0;
    164 
    165         return;
     144        if (!pDir) {
     145                errno = EINVAL;
     146                return;
     147        }
     148
     149        /* sanity check that this is a DIR pointer */
     150        if (pDir->dir_ulCookie != __DIRENT_COOKIE) {
     151                errno = EINVAL;
     152                return;
     153        }
     154
     155        /* close the WINDOWS32 directory handle */
     156        if (pDir->dir_hDirHandle != INVALID_HANDLE_VALUE)
     157                if (!FindClose(pDir->dir_hDirHandle))
     158                        errno = EBADF;
     159
     160        /* reset members which control readdir() */
     161        pDir->dir_hDirHandle = INVALID_HANDLE_VALUE;
     162        pDir->dir_nNumFiles = 0;
     163
     164        return;
    166165}
    167166
     
    169168telldir(DIR* pDir)
    170169{
    171         if (!pDir) {
    172                 errno = EINVAL;
    173                 return -1;
    174         }
    175 
    176         /* sanity check that this is a DIR pointer */
    177         if (pDir->dir_ulCookie != __DIRENT_COOKIE) {
    178                 errno = EINVAL;
    179                 return -1;
    180         }
    181 
    182         /* return number of times readdir() called */
    183         return pDir->dir_nNumFiles;
     170        if (!pDir) {
     171                errno = EINVAL;
     172                return -1;
     173        }
     174
     175        /* sanity check that this is a DIR pointer */
     176        if (pDir->dir_ulCookie != __DIRENT_COOKIE) {
     177                errno = EINVAL;
     178                return -1;
     179        }
     180
     181        /* return number of times readdir() called */
     182        return pDir->dir_nNumFiles;
    184183}
    185184
     
    187186seekdir(DIR* pDir, long nPosition)
    188187{
    189         if (!pDir)
    190                 return;
    191 
    192         /* sanity check that this is a DIR pointer */
    193         if (pDir->dir_ulCookie != __DIRENT_COOKIE)
    194                 return;
    195 
    196         /* go back to beginning of directory */
    197         rewinddir(pDir);
    198 
    199         /* loop until we have found position we care about */
    200         for (--nPosition; nPosition && readdir(pDir); nPosition--);
    201 
    202         /* flag invalid nPosition value */
    203         if (nPosition)
    204                 errno = EINVAL;
    205 
    206         return;
    207 }
     188        if (!pDir)
     189                return;
     190
     191        /* sanity check that this is a DIR pointer */
     192        if (pDir->dir_ulCookie != __DIRENT_COOKIE)
     193                return;
     194
     195        /* go back to beginning of directory */
     196        rewinddir(pDir);
     197
     198        /* loop until we have found position we care about */
     199        for (--nPosition; nPosition && readdir(pDir); nPosition--);
     200
     201        /* flag invalid nPosition value */
     202        if (nPosition)
     203                errno = EINVAL;
     204
     205        return;
     206}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette