< prev index next >

src/java.base/share/native/libjli/wildcard.c

Print this page


   1 /*
   2  * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  83  * supporting the use of wildcards on the command line and in the
  84  * CLASSPATH environment variable.  We do not support the use of
  85  * wildcards by applications that embed the JVM.
  86  */
  87 
  88 #include <stddef.h>
  89 #include <stdio.h>
  90 #include <stdlib.h>
  91 #include <string.h>
  92 #include <sys/types.h>
  93 #include "java.h"       /* Strictly for PATH_SEPARATOR/FILE_SEPARATOR */
  94 #include "jli_util.h"
  95 
  96 #ifdef _WIN32
  97 #include <windows.h>
  98 #else /* Unix */
  99 #include <unistd.h>
 100 #include <dirent.h>
 101 #endif /* Unix */
 102 






 103 static int
 104 exists(const char* filename)
 105 {
 106 #ifdef _WIN32
 107     return _access(filename, 0) == 0;
 108 #else
 109     return access(filename, F_OK) == 0;
 110 #endif
 111 }
 112 
 113 #define NEW_(TYPE) ((TYPE) JLI_MemAlloc(sizeof(struct TYPE##_)))
 114 
 115 /*
 116  * Wildcard directory iteration.
 117  * WildcardIterator_for(wildcard) returns an iterator.
 118  * Each call to that iterator's next() method returns the basename
 119  * of an entry in the wildcard's directory.  The basename's memory
 120  * belongs to the iterator.  The caller is responsible for prepending
 121  * the directory name and file separator, if necessary.
 122  * When done with the iterator, call the close method to clean up.


   1 /*
   2  * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  83  * supporting the use of wildcards on the command line and in the
  84  * CLASSPATH environment variable.  We do not support the use of
  85  * wildcards by applications that embed the JVM.
  86  */
  87 
  88 #include <stddef.h>
  89 #include <stdio.h>
  90 #include <stdlib.h>
  91 #include <string.h>
  92 #include <sys/types.h>
  93 #include "java.h"       /* Strictly for PATH_SEPARATOR/FILE_SEPARATOR */
  94 #include "jli_util.h"
  95 
  96 #ifdef _WIN32
  97 #include <windows.h>
  98 #else /* Unix */
  99 #include <unistd.h>
 100 #include <dirent.h>
 101 #endif /* Unix */
 102 
 103 #if defined(_AIX)
 104   #define DIR DIR64
 105   #define opendir opendir64
 106   #define closedir closedir64
 107 #endif
 108 
 109 static int
 110 exists(const char* filename)
 111 {
 112 #ifdef _WIN32
 113     return _access(filename, 0) == 0;
 114 #else
 115     return access(filename, F_OK) == 0;
 116 #endif
 117 }
 118 
 119 #define NEW_(TYPE) ((TYPE) JLI_MemAlloc(sizeof(struct TYPE##_)))
 120 
 121 /*
 122  * Wildcard directory iteration.
 123  * WildcardIterator_for(wildcard) returns an iterator.
 124  * Each call to that iterator's next() method returns the basename
 125  * of an entry in the wildcard's directory.  The basename's memory
 126  * belongs to the iterator.  The caller is responsible for prepending
 127  * the directory name and file separator, if necessary.
 128  * When done with the iterator, call the close method to clean up.


< prev index next >