Skip to content

Commit

Permalink
Various: use NUT_PATH_MAX instead of PATH_MAX, MAX_PATH, MAXPATHLEN, …
Browse files Browse the repository at this point in the history
…UNIX_PATH_MAX etc. [#2764]

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Jan 18, 2025
1 parent 81a87d1 commit e2b2140
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 31 deletions.
6 changes: 3 additions & 3 deletions clients/upssched.c
Original file line number Diff line number Diff line change
Expand Up @@ -970,14 +970,14 @@ static void start_daemon(TYPE_FD lockfd)
DWORD timeout_ms;
HANDLE rfds[32];

char module[MAX_PATH];
char module[NUT_PATH_MAX];
STARTUPINFO sinfo;
PROCESS_INFORMATION pinfo;
if( !GetModuleFileName(NULL,module,MAX_PATH) ) {
if (!GetModuleFileName(NULL, module, NUT_PATH_MAX)) {
fatal_with_errno(EXIT_FAILURE, "Can't retrieve module name");
}
memset(&sinfo,0,sizeof(sinfo));
if(!CreateProcess(module, NULL, NULL,NULL,FALSE,0,NULL,NULL,&sinfo,&pinfo)) {
if (!CreateProcess(module, NULL, NULL, NULL, FALSE, 0, NULL, NULL, &sinfo, &pinfo)) {
fatal_with_errno(EXIT_FAILURE, "Can't create child process");
}
pipefd = open_sock();
Expand Down
4 changes: 2 additions & 2 deletions common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1661,7 +1661,7 @@ int checkprocname(pid_t pid, const char *progname)
depending on the .exe path */
char * getfullpath(char * relative_path)
{
char buf[MAX_PATH];
char buf[NUT_PATH_MAX];
if ( GetModuleFileName(NULL, buf, sizeof(buf)) == 0 ) {
return NULL;
}
Expand All @@ -1682,7 +1682,7 @@ char * getfullpath(char * relative_path)
void writepid(const char *name)
{
#ifndef WIN32
char fn[SMALLBUF];
char fn[NUT_PATH_MAX];
FILE *pidf;
mode_t mask;

Expand Down
6 changes: 3 additions & 3 deletions common/nutstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ static const char* getTmpDirPath() {

#ifdef WIN32
/* Suggestions from https://sourceforge.net/p/mingw/bugs/666/ */
static char pathbuf[MAX_PATH];
static char pathbuf[NUT_PATH_MAX];
int i;
#endif

Expand All @@ -255,7 +255,7 @@ static const char* getTmpDirPath() {

#ifdef WIN32
i = GetTempPathA(sizeof(pathbuf), pathbuf);
if ((i > 0) && (i < MAX_PATH) && checkExistsWritableDir(pathbuf))
if ((i > 0) && (i < NUT_PATH_MAX) && checkExistsWritableDir(pathbuf))
return (const char *)pathbuf;
#endif

Expand Down Expand Up @@ -328,7 +328,7 @@ NutFile::NutFile(anonymous_t):
/* Suggestions from https://sourceforge.net/p/mingw/bugs/666/ because
* msvcrt tmpfile() uses C: root dir and lacks permissions to actually
* use it, and mingw tends to call that OS method so far */
char filename[MAX_PATH];
char filename[NUT_PATH_MAX];
memset(filename, 0, sizeof(filename));

GetTempFileNameA(m_tmp_dir.c_str(), "nuttemp", 0, filename);
Expand Down
10 changes: 5 additions & 5 deletions drivers/hwmon_ina219.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ upsdrv_info_t upsdrv_info = {
/**
* @brief Path usually pointing to /sys/class/hwmon/hwmonX.
*/
static char ina219_base_path[PATH_MAX];
static char ina219_base_path[NUT_PATH_MAX];

/**
* @brief Threshold for detection of LB status.
Expand Down Expand Up @@ -128,7 +128,7 @@ static int file_read_number(const char *path, int *value)

static int detect_ina219(const char *ina219_dir)
{
char namepath[PATH_MAX];
char namepath[NUT_PATH_MAX];

upsdebugx(3, "checking %s", ina219_dir);

Expand Down Expand Up @@ -166,7 +166,7 @@ static int scan_hwmon_ina219(const char *sysfs_hwmon_dir)
}

while ((entry = readdir(sysfs)) != NULL) {
char hwmon_dir[PATH_MAX];
char hwmon_dir[NUT_PATH_MAX];

if (entry->d_type != DT_DIR && entry->d_type != DT_LNK) {
upsdebugx(3, "path %s/%s is not directory/symlink", sysfs_hwmon_dir,
Expand Down Expand Up @@ -204,10 +204,10 @@ static int update_intvar(
const char *name,
int *value)
{
char path[PATH_MAX];
char path[NUT_PATH_MAX];
int ret;

if (snprintf(path, sizeof(path), "%s/%s", base_path, name) >= PATH_MAX) {
if (snprintf(path, sizeof(path), "%s/%s", base_path, name) >= NUT_PATH_MAX) {
errno = ENAMETOOLONG;
upslog_with_errno(LOG_ERR, "snprintf(%s/%s) has failed", base_path, name);
return -ENAMETOOLONG;
Expand Down
2 changes: 1 addition & 1 deletion drivers/nhs_ser.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ static unsigned int max_checktime = 6000000; /* max wait time: 6 seconds */
static unsigned int send_extended = 0;
static int bwritten = 0;
static unsigned char datapacket[DATAPACKETSIZE];
static char porta[PATH_MAX] = DEFAULTPORT;
static char porta[NUT_PATH_MAX] = DEFAULTPORT;
static int baudrate = DEFAULTBAUD;
static float minpower = 0;
static float maxpower = 0;
Expand Down
7 changes: 0 additions & 7 deletions include/wincompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,4 @@ speed_t cfgetospeed(const struct termios *t);
#define TIOCM_RI TIOCM_RNG /* at least that's the definition in Linux */
#define TIOCM_CD MS_RLSD_ON /*0x0080*/

#if !defined(PATH_MAX) && defined(MAX_PATH)
/* PATH_MAX is the POSIX equivalent for Microsoft's MAX_PATH
* both should be defined in (mingw) limits.h
*/
# define PATH_MAX MAX_PATH
#endif

#endif /* NUT_WINCOMPAT_H */
16 changes: 8 additions & 8 deletions scripts/Windows/wininit.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static const char * makearg_debug(void)
/* return PID of created process or 0 on failure */
static DWORD run_drivers(void)
{
char command[MAX_PATH];
char command[NUT_PATH_MAX];
char *path;

path = getfullpath(PATH_BIN);
Expand All @@ -162,7 +162,7 @@ static DWORD run_drivers(void)
/* return PID of created process or 0 on failure */
static DWORD stop_drivers(void)
{
char command[MAX_PATH];
char command[NUT_PATH_MAX];
char *path;

path = getfullpath(PATH_BIN);
Expand All @@ -179,7 +179,7 @@ static DWORD stop_drivers(void)
/* return PID of created process or 0 on failure */
static void run_upsd(void)
{
char command[MAX_PATH];
char command[NUT_PATH_MAX];
char *path;

path = getfullpath(PATH_SBIN);
Expand All @@ -201,7 +201,7 @@ static void stop_upsd(void)
/* return PID of created process or 0 on failure */
static void run_upsmon(void)
{
char command[MAX_PATH];
char command[NUT_PATH_MAX];
char *path;

path = getfullpath(PATH_SBIN);
Expand All @@ -223,7 +223,7 @@ static void stop_upsmon(void)
/* Return 0 if powerdown flag is set */
static DWORD test_powerdownflag(void)
{
char command[MAX_PATH];
char command[NUT_PATH_MAX];
char *path;
STARTUPINFO StartupInfo;
PROCESS_INFORMATION ProcessInformation;
Expand Down Expand Up @@ -279,7 +279,7 @@ static DWORD test_powerdownflag(void)

static DWORD shutdown_ups(void)
{
char command[MAX_PATH];
char command[NUT_PATH_MAX];
char *path;

path = getfullpath(PATH_BIN);
Expand Down Expand Up @@ -373,9 +373,9 @@ static int SvcInstall(const char * SvcName, const char * args)
{
SC_HANDLE SCManager;
SC_HANDLE Service;
TCHAR Path[MAX_PATH];
TCHAR Path[NUT_PATH_MAX];

if (!GetModuleFileName(NULL, Path, MAX_PATH)) {
if (!GetModuleFileName(NULL, Path, NUT_PATH_MAX)) {
printf("Cannot install service (%d)\n", (int)GetLastError());
return EXIT_FAILURE;
}
Expand Down
4 changes: 2 additions & 2 deletions server/sstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ TYPE_FD sstate_connect(upstype_t *ups)
upsdebugx(2, "%s: failed to connect() UNIX socket %s (%s)",
__func__, NUT_STRARG(ups->fn), sa.sun_path);
} else {
char cwd[PATH_MAX+1];
char cwd[NUT_PATH_MAX+1];
upsdebugx(2, "%s: failed to connect() UNIX socket %s (%s/%s)",
__func__, NUT_STRARG(ups->fn),
getcwd(cwd, sizeof(cwd)), sa.sun_path);
Expand All @@ -241,7 +241,7 @@ TYPE_FD sstate_connect(upstype_t *ups)
upslog_with_errno(LOG_ERR, "Can't connect to UPS [%s] (%s)",
ups->name, ups->fn);
} else {
char cwd[PATH_MAX+1];
char cwd[NUT_PATH_MAX+1];
upslog_with_errno(LOG_ERR, "Can't connect to UPS [%s] (%s/%s)",
ups->name, getcwd(cwd, sizeof(cwd)), ups->fn);
}
Expand Down

0 comments on commit e2b2140

Please sign in to comment.