~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to osdep/glob-win.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2012-01-12 22:23:28 UTC
  • mfrom: (0.4.7 sid)
  • mto: This revision was merged to the branch mainline in revision 76.
  • Revision ID: package-import@ubuntu.com-20120112222328-8jqdyodym3p84ygu
Tags: 2:1.0~rc4.dfsg1+svn34540-1
* New upstream snapshot
* upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include "glob.h"
28
28
 
29
29
int glob(const char *pattern, int flags,
30
 
          int (*errfunc)(const char *epath, int eerrno), glob_t *pglob)
 
30
         int (*errfunc)(const char *epath, int eerrno), glob_t *pglob)
31
31
{
32
 
        HANDLE searchhndl;
 
32
    HANDLE searchhndl;
33
33
    WIN32_FIND_DATA found_file;
34
 
        if(errfunc)printf("glob():ERROR:Sorry errfunc not supported by this implementation\n");
35
 
        if(flags)printf("glob():ERROR:Sorry no flags supported by this globimplementation\n");
36
 
        //printf("PATTERN \"%s\"\n",pattern);
37
 
        pglob->gl_pathc = 0;
38
 
        searchhndl = FindFirstFile( pattern,&found_file);
39
 
    if(searchhndl == INVALID_HANDLE_VALUE)
40
 
        {
41
 
                if(GetLastError() == ERROR_FILE_NOT_FOUND)
42
 
                {
43
 
                        pglob->gl_pathc = 0;
44
 
                    //printf("could not find a file matching your search criteria\n");
45
 
                return 1;
46
 
                }
47
 
                else
48
 
                {
49
 
                        //printf("glob():ERROR:FindFirstFile: %i\n",GetLastError());
50
 
                        return 1;
51
 
                }
52
 
         }
53
 
    pglob->gl_pathv = malloc(sizeof(char*));
 
34
    if (errfunc)
 
35
        printf("glob():ERROR:Sorry errfunc not supported by this implementation\n");
 
36
    if (flags)
 
37
        printf("glob():ERROR:Sorry no flags supported by this globimplementation\n");
 
38
    //printf("PATTERN \"%s\"\n",pattern);
 
39
    pglob->gl_pathc = 0;
 
40
    searchhndl      = FindFirstFile(pattern, &found_file);
 
41
    if (searchhndl == INVALID_HANDLE_VALUE) {
 
42
        if (GetLastError() == ERROR_FILE_NOT_FOUND) {
 
43
            pglob->gl_pathc = 0;
 
44
            //printf("could not find a file matching your search criteria\n");
 
45
            return 1;
 
46
        } else {
 
47
            //printf("glob():ERROR:FindFirstFile: %i\n",GetLastError());
 
48
            return 1;
 
49
        }
 
50
    }
 
51
    pglob->gl_pathv    = malloc(sizeof(char *));
54
52
    pglob->gl_pathv[0] = strdup(found_file.cFileName);
55
53
    pglob->gl_pathc++;
56
 
    while(1)
57
 
    {
58
 
                if(!FindNextFile(searchhndl,&found_file))
59
 
                {
60
 
                        if(GetLastError()==ERROR_NO_MORE_FILES)
61
 
                        {
62
 
                                //printf("glob(): no more files found\n");
 
54
    while (1) {
 
55
        if (!FindNextFile(searchhndl, &found_file)) {
 
56
            if (GetLastError() == ERROR_NO_MORE_FILES) {
 
57
                //printf("glob(): no more files found\n");
63
58
                break;
64
 
                        }
65
 
                        else
66
 
                        {
67
 
                                //printf("glob():ERROR:FindNextFile:%i\n",GetLastError());
68
 
                                return 1;
69
 
                        }
70
 
                }
71
 
                else
72
 
                {
 
59
            } else {
 
60
                //printf("glob():ERROR:FindNextFile:%i\n",GetLastError());
 
61
                return 1;
 
62
            }
 
63
        } else {
73
64
            //printf("glob: found file %s\n",found_file.cFileName);
74
65
            pglob->gl_pathc++;
75
 
            pglob->gl_pathv = realloc(pglob->gl_pathv,pglob->gl_pathc * sizeof(char*));
76
 
            pglob->gl_pathv[pglob->gl_pathc-1] = strdup(found_file.cFileName);
77
 
                }
 
66
            pglob->gl_pathv = realloc(pglob->gl_pathv, pglob->gl_pathc * sizeof(char *));
 
67
            pglob->gl_pathv[pglob->gl_pathc - 1] = strdup(found_file.cFileName);
 
68
        }
78
69
    }
79
70
    FindClose(searchhndl);
80
71
    return 0;
82
73
 
83
74
void globfree(glob_t *pglob)
84
75
{
85
 
        int i;
86
 
        for(i=0; i <pglob->gl_pathc ;i++)
87
 
        {
88
 
                free(pglob->gl_pathv[i]);
89
 
        }
90
 
        free(pglob->gl_pathv);
 
76
    int i;
 
77
    for (i = 0; i < pglob->gl_pathc; i++)
 
78
        free(pglob->gl_pathv[i]);
 
79
    free(pglob->gl_pathv);
91
80
}
92
81
 
93
82
#if 0
94
 
int main(void){
95
 
   glob_t        gg;
96
 
   printf("globtest\n");
97
 
   glob( "*.jpeg",0,NULL,&gg );
98
 
   {
 
83
int main(void)
 
84
{
 
85
    glob_t gg;
 
86
    printf("globtest\n");
 
87
    glob("*.jpeg", 0, NULL, &gg);
 
88
    {
99
89
        int i;
100
 
        for(i=0;i<gg.gl_pathc;i++)printf("GLOBED:%i %s\n",i,gg.gl_pathv[i]);
 
90
        for (i = 0; i < gg.gl_pathc; i++)
 
91
            printf("GLOBED:%i %s\n", i, gg.gl_pathv[i]);
101
92
    }
102
 
   globfree(&gg);
 
93
    globfree(&gg);
103
94
 
104
 
   return 0;
 
95
    return 0;
105
96
}
 
97
 
106
98
#endif