< prev index next >
src/java.base/unix/native/libjava/UnixFileSystem_md.c
Print this page
*** 1,7 ****
/*
! * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 63,73 ****
#define NAME_MAX MAXNAMLEN
#endif
#if defined(_ALLBSD_SOURCE)
#define dirent64 dirent
! #define readdir64_r readdir_r
#define stat64 stat
#ifndef MACOSX
#define statvfs64 statvfs
#endif
#endif
--- 63,73 ----
#define NAME_MAX MAXNAMLEN
#endif
#if defined(_ALLBSD_SOURCE)
#define dirent64 dirent
! #define readdir64 readdir
#define stat64 stat
#ifndef MACOSX
#define statvfs64 statvfs
#endif
#endif
*** 310,320 ****
Java_java_io_UnixFileSystem_list(JNIEnv *env, jobject this,
jobject file)
{
DIR *dir = NULL;
struct dirent64 *ptr;
- struct dirent64 *result;
int len, maxlen;
jobjectArray rv, old;
jclass str_class;
str_class = JNU_ClassString(env);
--- 310,319 ----
*** 323,347 ****
WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
dir = opendir(path);
} END_PLATFORM_STRING(env, path);
if (dir == NULL) return NULL;
- ptr = malloc(sizeof(struct dirent64) + (PATH_MAX + 1));
- if (ptr == NULL) {
- JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
- closedir(dir);
- return NULL;
- }
-
/* Allocate an initial String array */
len = 0;
maxlen = 16;
rv = (*env)->NewObjectArray(env, maxlen, str_class, NULL);
if (rv == NULL) goto error;
/* Scan the directory */
! while ((readdir64_r(dir, ptr, &result) == 0) && (result != NULL)) {
jstring name;
if (!strcmp(ptr->d_name, ".") || !strcmp(ptr->d_name, ".."))
continue;
if (len == maxlen) {
old = rv;
--- 322,339 ----
WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
dir = opendir(path);
} END_PLATFORM_STRING(env, path);
if (dir == NULL) return NULL;
/* Allocate an initial String array */
len = 0;
maxlen = 16;
rv = (*env)->NewObjectArray(env, maxlen, str_class, NULL);
if (rv == NULL) goto error;
/* Scan the directory */
! while ((ptr = readdir64(dir)) != NULL) {
jstring name;
if (!strcmp(ptr->d_name, ".") || !strcmp(ptr->d_name, ".."))
continue;
if (len == maxlen) {
old = rv;
*** 358,368 ****
if (name == NULL) goto error;
(*env)->SetObjectArrayElement(env, rv, len++, name);
(*env)->DeleteLocalRef(env, name);
}
closedir(dir);
- free(ptr);
/* Copy the final results into an appropriately-sized array */
old = rv;
rv = (*env)->NewObjectArray(env, len, str_class, NULL);
if (rv == NULL) {
--- 350,359 ----
*** 373,383 ****
}
return rv;
error:
closedir(dir);
- free(ptr);
return NULL;
}
JNIEXPORT jboolean JNICALL
--- 364,373 ----
< prev index next >