From 51e2e7f8d5497633625668043c4f6faae467ea5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 29 Sep 2020 10:24:41 +0200 Subject: [PATCH] Remove our usage of ssize_t --- Core/HLE/sceIo.cpp | 4 ++-- ext/native/base/basictypes.h | 2 -- ext/native/base/buffer.cpp | 8 ++++---- ext/native/base/buffer.h | 3 +-- ext/native/base/stringutil.h | 3 --- ext/native/file/fd_util.cpp | 10 +++++----- ext/native/file/fd_util.h | 15 ++++++--------- 7 files changed, 18 insertions(+), 27 deletions(-) diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index e9b76785b9..9fd546d131 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -967,8 +967,8 @@ static u32 npdrmRead(FileNode *f, u8 *data, int size) { block = pgd->file_offset/pgd->block_size; offset = pgd->file_offset%pgd->block_size; - if (size > pgd->data_size) - size = pgd->data_size; + if (size > (int)pgd->data_size) + size = (int)pgd->data_size; remain_size = size; while(remain_size){ diff --git a/ext/native/base/basictypes.h b/ext/native/base/basictypes.h index 2f9c7d0321..b104506eaa 100644 --- a/ext/native/base/basictypes.h +++ b/ext/native/base/basictypes.h @@ -30,8 +30,6 @@ #ifdef _WIN32 -typedef intptr_t ssize_t; - #include #endif // _WIN32 diff --git a/ext/native/base/buffer.cpp b/ext/native/base/buffer.cpp index 86ccd22480..9598dcbe00 100644 --- a/ext/native/base/buffer.cpp +++ b/ext/native/base/buffer.cpp @@ -26,7 +26,7 @@ Buffer::Buffer() { } Buffer::~Buffer() { } -char *Buffer::Append(ssize_t length) { +char *Buffer::Append(size_t length) { if (length > 0) { size_t old_size = data_.size(); data_.resize(old_size + length); @@ -120,8 +120,8 @@ void Buffer::Printf(const char *fmt, ...) { char buffer[2048]; va_list vl; va_start(vl, fmt); - ssize_t retval = vsnprintf(buffer, sizeof(buffer), fmt, vl); - if (retval >= (ssize_t)sizeof(buffer)) { + size_t retval = vsnprintf(buffer, sizeof(buffer), fmt, vl); + if ((int)retval >= (int)sizeof(buffer)) { // Output was truncated. TODO: Do something. ERROR_LOG(IO, "Buffer::Printf truncated output"); } @@ -135,7 +135,7 @@ void Buffer::Printf(const char *fmt, ...) { bool Buffer::Flush(int fd) { // Look into using send() directly. - bool success = (ssize_t)data_.size() == fd_util::WriteLine(fd, &data_[0], data_.size()); + bool success = data_.size() == fd_util::WriteLine(fd, &data_[0], data_.size()); if (success) { data_.resize(0); } diff --git a/ext/native/base/buffer.h b/ext/native/base/buffer.h index 96abfbbd3f..63ab44b907 100644 --- a/ext/native/base/buffer.h +++ b/ext/native/base/buffer.h @@ -16,8 +16,7 @@ class Buffer { // Write max [length] bytes to the returned pointer. // Any other operation on this Buffer invalidates the pointer. - char *Append(ssize_t length); - char *Append(size_t length) { return Append((ssize_t)length); } + char *Append(size_t length); // These work pretty much like you'd expect. void Append(const char *str); // str null-terminated. The null is not copied. diff --git a/ext/native/base/stringutil.h b/ext/native/base/stringutil.h index 3a64058838..0e293a0f43 100644 --- a/ext/native/base/stringutil.h +++ b/ext/native/base/stringutil.h @@ -46,9 +46,6 @@ inline bool endsWithNoCase(const std::string &str, const std::string &what) { void DataToHexString(const uint8_t *data, size_t size, std::string *output); void DataToHexString(const char* prefix, uint32_t startAddr, const uint8_t* data, size_t size, std::string* output); -inline void StringToHexString(const std::string &data, std::string *output) { - DataToHexString((uint8_t *)(&data[0]), data.size(), output); -} std::string StringFromFormat(const char* format, ...); std::string StringFromInt(int value); diff --git a/ext/native/file/fd_util.cpp b/ext/native/file/fd_util.cpp index 1b47c215fc..e7726392d4 100644 --- a/ext/native/file/fd_util.cpp +++ b/ext/native/file/fd_util.cpp @@ -25,12 +25,12 @@ namespace fd_util { // Slow as hell and should only be used for prototyping. // Reads from a socket, up to an '\n'. This means that if the line ends // with '\r', the '\r' will be returned. -ssize_t ReadLine(int fd, char *vptr, size_t buf_size) { +size_t ReadLine(int fd, char *vptr, size_t buf_size) { char *buffer = vptr; size_t n; for (n = 1; n < buf_size; n++) { char c; - ssize_t rc; + size_t rc; if ((rc = read(fd, &c, 1)) == 1) { *buffer++ = c; if (c == '\n') @@ -54,7 +54,7 @@ ssize_t ReadLine(int fd, char *vptr, size_t buf_size) { } // Misnamed, it just writes raw data in a retry loop. -ssize_t WriteLine(int fd, const char *vptr, size_t n) { +size_t WriteLine(int fd, const char *vptr, size_t n) { const char *buffer = vptr; size_t nleft = n; @@ -73,11 +73,11 @@ ssize_t WriteLine(int fd, const char *vptr, size_t n) { return n; } -ssize_t WriteLine(int fd, const char *buffer) { +size_t WriteLine(int fd, const char *buffer) { return WriteLine(fd, buffer, strlen(buffer)); } -ssize_t Write(int fd, const std::string &str) { +size_t Write(int fd, const std::string &str) { return WriteLine(fd, str.c_str(), str.size()); } diff --git a/ext/native/file/fd_util.h b/ext/native/file/fd_util.h index 922a50eb70..5160c4e157 100644 --- a/ext/native/file/fd_util.h +++ b/ext/native/file/fd_util.h @@ -1,7 +1,6 @@ -#ifndef _FD_UTIL -#define _FD_UTIL +#pragma once -#include +#include #include #include "base/basictypes.h" @@ -9,12 +8,12 @@ namespace fd_util { // Slow as hell and should only be used for prototyping. -ssize_t ReadLine(int fd, char *buffer, size_t buf_size); +size_t ReadLine(int fd, char *buffer, size_t buf_size); // Decently fast. -ssize_t WriteLine(int fd, const char *buffer, size_t buf_size); -ssize_t WriteLine(int fd, const char *buffer); -ssize_t Write(int fd, const std::string &str); +size_t WriteLine(int fd, const char *buffer, size_t buf_size); +size_t WriteLine(int fd, const char *buffer); +size_t Write(int fd, const std::string &str); // Returns true if the fd became ready, false if it didn't or // if there was another error. @@ -25,5 +24,3 @@ void SetNonBlocking(int fd, bool non_blocking); std::string GetLocalIP(int sock); } // fd_util - -#endif // _FD_UTIL