8183227: read/write APIs in class os shall return ssize_t

Reviewed-by: fparain, rehn
This commit is contained in:
Harold Seigel 2022-01-10 13:18:41 +00:00
parent 6613ce64d7
commit 4ff6720573
10 changed files with 34 additions and 35 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2022, 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
@ -385,7 +385,7 @@ LinuxAttachOperation* LinuxAttachListener::dequeue() {
// write the given buffer to the socket
int LinuxAttachListener::write_fully(int s, char* buf, int len) {
do {
int n = ::write(s, buf, len);
ssize_t n = ::write(s, buf, len);
if (n == -1) {
if (errno != EINTR) return -1;
} else {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2022, 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
@ -679,9 +679,9 @@ FILE* os::open(int fd, const char* mode) {
return ::fdopen(fd, mode);
}
size_t os::write(int fd, const void *buf, unsigned int nBytes) {
size_t res;
RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res);
ssize_t os::write(int fd, const void *buf, unsigned int nBytes) {
ssize_t res;
RESTARTABLE(::write(fd, buf, (size_t) nBytes), res);
return res;
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2021 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@ -98,21 +98,20 @@ static void save_memory_to_file(char* addr, size_t size) {
const char* destfile = PerfMemory::get_perfdata_file_path();
assert(destfile[0] != '\0', "invalid PerfData file path");
int result;
int fd;
RESTARTABLE(os::open(destfile, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR),
result);
if (result == OS_ERR) {
RESTARTABLE(os::open(destfile, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR), fd);
if (fd == OS_ERR) {
if (PrintMiscellaneous && Verbose) {
warning("Could not create Perfdata save file: %s: %s\n",
destfile, os::strerror(errno));
}
} else {
int fd = result;
ssize_t result;
for (size_t remaining = size; remaining > 0;) {
RESTARTABLE(::write(fd, addr, remaining), result);
result = os::write(fd, addr, remaining);
if (result == OS_ERR) {
if (PrintMiscellaneous && Verbose) {
warning("Could not write Perfdata save file: %s: %s\n",
@ -125,7 +124,7 @@ static void save_memory_to_file(char* addr, size_t size) {
addr += result;
}
result = ::close(fd);
result = os::close(fd);
if (PrintMiscellaneous && Verbose) {
if (result == OS_ERR) {
warning("Could not close %s: %s\n", destfile, os::strerror(errno));
@ -842,9 +841,9 @@ static int create_sharedmem_resources(const char* dirname, const char* filename,
// Open the filename in the current directory.
// Cannot use O_TRUNC here; truncation of an existing file has to happen
// after the is_file_secure() check below.
int result;
RESTARTABLE(os::open(filename, O_RDWR|O_CREAT|O_NOFOLLOW, S_IRUSR|S_IWUSR), result);
if (result == OS_ERR) {
int fd;
RESTARTABLE(os::open(filename, O_RDWR|O_CREAT|O_NOFOLLOW, S_IRUSR|S_IWUSR), fd);
if (fd == OS_ERR) {
if (PrintMiscellaneous && Verbose) {
if (errno == ELOOP) {
warning("file %s is a symlink and is not secure\n", filename);
@ -860,15 +859,14 @@ static int create_sharedmem_resources(const char* dirname, const char* filename,
// close the directory and reset the current working directory
close_directory_secure_cwd(dirp, saved_cwd_fd);
// save the file descriptor
int fd = result;
// check to see if the file is secure
if (!is_file_secure(fd, filename)) {
::close(fd);
return -1;
}
ssize_t result;
// truncate the file to get rid of any existing data
RESTARTABLE(::ftruncate(fd, (off_t)0), result);
if (result == OS_ERR) {
@ -895,7 +893,7 @@ static int create_sharedmem_resources(const char* dirname, const char* filename,
int zero_int = 0;
result = (int)os::seek_to_file_offset(fd, (jlong)(seekpos));
if (result == -1 ) break;
RESTARTABLE(::write(fd, &zero_int, 1), result);
result = os::write(fd, &zero_int, 1);
if (result != 1) {
if (errno == ENOSPC) {
warning("Insufficient space for shared memory file:\n %s\nTry using the -Djava.io.tmpdir= option to select an alternate temp location.\n", filename);
@ -907,7 +905,7 @@ static int create_sharedmem_resources(const char* dirname, const char* filename,
if (result != -1) {
return fd;
} else {
::close(fd);
os::close(fd);
return -1;
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2022, 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
@ -4758,7 +4758,7 @@ FILE* os::open(int fd, const char* mode) {
return ::_fdopen(fd, mode);
}
size_t os::write(int fd, const void *buf, unsigned int nBytes) {
ssize_t os::write(int fd, const void *buf, unsigned int nBytes) {
return ::write(fd, buf, nBytes);
}

View file

@ -1613,8 +1613,8 @@ size_t FileMapInfo::write_heap_regions(GrowableArray<MemRegion>* regions,
void FileMapInfo::write_bytes(const void* buffer, size_t nbytes) {
assert(_file_open, "must be");
size_t n = os::write(_fd, buffer, (unsigned int)nbytes);
if (n != nbytes) {
ssize_t n = os::write(_fd, buffer, (unsigned int)nbytes);
if (n < 0 || (size_t)n != nbytes) {
// If the shared archive is corrupted, close it and remove it.
close();
remove(_full_path);

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2022, 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
@ -76,7 +76,7 @@ inline void StreamWriterHost<Adapter, AP>::write_bytes(const u1* buf, intptr_t l
assert(len >= 0, "invariant");
while (len > 0) {
const unsigned int nBytes = len > INT_MAX ? INT_MAX : (unsigned int)len;
const ssize_t num_written = (ssize_t)os::write(_fd, buf, nBytes);
const ssize_t num_written = os::write(_fd, buf, nBytes);
guarantee(num_written > 0, "Nothing got written, or os::write() failed");
_stream_pos += num_written;
len -= num_written;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2022, 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
@ -2836,7 +2836,7 @@ void jio_print(const char* s, size_t len) {
jio_fprintf(defaultStream::output_stream(), "%.*s", (int)len, s);
} else {
// Make an unused local variable to avoid warning from gcc compiler.
size_t count = ::write(defaultStream::output_fd(), s, (int)len);
ssize_t count = os::write(defaultStream::output_fd(), s, (int)len);
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2022, 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
@ -565,7 +565,7 @@ class os: AllStatic {
static ssize_t read(int fd, void *buf, unsigned int nBytes);
static ssize_t read_at(int fd, void *buf, unsigned int nBytes, jlong offset);
static size_t write(int fd, const void *buf, unsigned int nBytes);
static ssize_t write(int fd, const void *buf, unsigned int nBytes);
// Reading directories.
static DIR* opendir(const char* dirname);

View file

@ -1,4 +1,5 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@ -54,7 +55,7 @@ char const* FileWriter::write_buf(char* buf, ssize_t size) {
assert(_fd >= 0, "Must be open");
assert(size > 0, "Must write at least one byte");
ssize_t n = (ssize_t) os::write(_fd, buf, (uint) size);
ssize_t n = os::write(_fd, buf, (uint) size);
if (n <= 0) {
return os::strerror(errno);

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2022, 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
@ -614,7 +614,7 @@ void fileStream::flush() {
void fdStream::write(const char* s, size_t len) {
if (_fd != -1) {
// Make an unused local variable to avoid warning from gcc compiler.
size_t count = ::write(_fd, s, (int)len);
ssize_t count = ::write(_fd, s, (int)len);
update_position(s, len);
}
}