From 359e0ab945b7da817a8e81f2d1ac84963cdb8080 Mon Sep 17 00:00:00 2001 From: Victor Forsiuk Date: Tue, 17 Sep 2024 09:06:01 +0300 Subject: [PATCH 1/2] Remove unused functions from win/rlimit.c --- src/win/rlimit.c | 43 ------------------------------------------- src/win/rlimit.h | 6 +----- 2 files changed, 1 insertion(+), 48 deletions(-) diff --git a/src/win/rlimit.c b/src/win/rlimit.c index 362aadc84285..ab47830a1052 100644 --- a/src/win/rlimit.c +++ b/src/win/rlimit.c @@ -102,49 +102,6 @@ int setrlimit(int resource, const struct rlimit *rlp) return 0; // success } -// Wrap the real fwrite() with this rfwrite() function, which is -// resource limit aware. -// -size_t rfwrite(const void *buffer, size_t size, size_t count, FILE *stream) -{ - // Convert the count to a large integer (64 bit integer) - const __int64 liByteCount = (__int64)count; - - // Get the current file position - const __int64 liPosition = (__int64)ftell(stream); - - // Check to make sure the write will not exceed the RLIMIT_FSIZE limit. - if(liPosition + liByteCount > rlimits[RLIMIT_FSIZE].rlim_cur) - { - // Report an error - return 0; - } - // Do the actual write the user requested - return fwrite(buffer, size, count, stream); -} - -// Wrap the real _write() function with the _rwrite() function -// which is resource aware. -// -int _rwrite(int handle, const void *buffer, unsigned int count) -{ - // Convert the count to a large integer - const int64_t liByteCount = (__int64)count; - - // Get the Current file position - const int64_t liPosition = (__int64)_tell(handle); - - // Check to make sure the write will not exceed the RLIMIT_FSIZE limit - if(liPosition + liByteCount > rlimits[RLIMIT_FSIZE].rlim_cur) - { - // Report an error - return 0; - } - - // Do the actual write the user requested - return _write(handle, buffer, count); -} - // clang-format off // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py // vim: shiftwidth=2 expandtab tabstop=2 cindent diff --git a/src/win/rlimit.h b/src/win/rlimit.h index 8f7abdcaea66..7a3d68f253d4 100644 --- a/src/win/rlimit.h +++ b/src/win/rlimit.h @@ -1,6 +1,6 @@ /* This file is part of darktable, - Copyright (C) 2017-2020 darktable developers. + Copyright (C) 2017-2024 darktable developers. darktable is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -51,12 +51,8 @@ typedef struct rlimit rlimit_t; int getrlimit(int resource, struct rlimit *); int setrlimit(int resource, const struct rlimit *); -size_t rfwrite(const void *buffer, size_t size, size_t count, FILE *stream); -int _rwrite(int handle, const void *buffer, unsigned int count); - // clang-format off // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py // vim: shiftwidth=2 expandtab tabstop=2 cindent // kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified; // clang-format on - From b803888b976ff2c12af614080ed61309669e70d0 Mon Sep 17 00:00:00 2001 From: Victor Forsiuk Date: Tue, 17 Sep 2024 09:28:52 +0300 Subject: [PATCH 2/2] Optimize comments --- src/win/rlimit.h | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/win/rlimit.h b/src/win/rlimit.h index 7a3d68f253d4..b812a5ea4e6c 100644 --- a/src/win/rlimit.h +++ b/src/win/rlimit.h @@ -20,34 +20,25 @@ #include -#define RLIMIT_CPU 0 /* limit on CPU time per process */ -#define RLIMIT_FSIZE 1 /* limit on file size */ -#define RLIMIT_DATA 2 /* limit on data segment size */ -#define RLIMIT_STACK 3 /* limit on process stack size */ -#define RLIMIT_CORE 4 /* limit on size of core dump file */ -#define RLIMIT_NOFILE 5 /* limit on number of open files */ -#define RLIMIT_AS 6 /* limit on process total address space size */ +#define RLIMIT_CPU 0 // limit on CPU time per process +#define RLIMIT_FSIZE 1 // limit on file size +#define RLIMIT_DATA 2 // limit on data segment size +#define RLIMIT_STACK 3 // limit on process stack size +#define RLIMIT_CORE 4 // limit on size of core dump file +#define RLIMIT_NOFILE 5 // limit on number of open files +#define RLIMIT_AS 6 // limit on process total address space size #define RLIMIT_VMEM RLIMIT_AS #define RLIM_NLIMITS 7 #define RLIM_INFINITY (~0UL) -/* - * process resource limits definitions - */ - struct rlimit { - // LARGE_INTEGER rlim_cur; - // LARGE_INTEGER rlim_max; - __int64 rlim_cur; - __int64 rlim_max; + __int64 rlim_cur; // current (soft) limit + __int64 rlim_max; // maximum value for rlim_cur (hard limit) }; typedef struct rlimit rlimit_t; -/* - * Prototypes - */ int getrlimit(int resource, struct rlimit *); int setrlimit(int resource, const struct rlimit *);