Skip to content
Snippets Groups Projects
Commit c53935bd authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Move sbbs/smblib/scfglib dependent functions from nopen.c to logfile.cpp

Move the nopen-specific constants from sbbsdefs.h to nopen.c

This helps svdmodem to use findstr->nopen without more sbbs/smblib deps
parent 4ef40e44
Branches
Tags
No related merge requests found
Pipeline #4994 failed
......@@ -313,3 +313,46 @@ void sbbs_t::errormsg(int line, const char* function, const char *src, const cha
errormsg_inside=false;
}
/****************************************************************************/
/* Open a log file for append, supporting log rotation based on size */
/****************************************************************************/
extern "C" FILE* fopenlog(scfg_t* cfg, const char* path)
{
const int mode = O_WRONLY|O_CREAT|O_APPEND;
int file;
FILE* fp;
if((fp = fnopen(&file, path, mode)) == NULL)
return NULL;
if(cfg->max_log_size && cfg->max_logs_kept && filelength(file) >= (off_t)cfg->max_log_size) {
#ifdef _WIN32 // Can't rename an open file on Windows
fclose(fp);
#endif
backup(path, cfg->max_logs_kept, /* rename: */TRUE);
#ifndef _WIN32
fclose(fp);
#endif
if((fp = fnopen(NULL, path, mode)) == NULL)
return NULL;
}
return fp;
}
// Write to a log file and may close it if reached max size
extern "C" size_t fwritelog(scfg_t* cfg, void* buf, size_t size, FILE** fp)
{
size_t result = fwrite(buf, 1, size, *fp);
if(cfg->max_log_size && ftell(*fp) >= (off_t)cfg->max_log_size) {
fclose(*fp);
*fp = NULL;
}
return result;
}
extern "C" void fcloselog(FILE* fp)
{
fclose(fp);
}
......@@ -19,11 +19,15 @@
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
#include "genwrap.h"
#include "dirwrap.h"
#include "filewrap.h"
#include "sockwrap.h"
#include "sbbsdefs.h"
#include "nopen.h"
#define FNOPEN_BUF_SIZE (2*1024)
#define LOOP_NOPEN 50 /* Retries before file access denied */
/****************************************************************************/
/* Network open function. Opens all files DENYALL, DENYWRITE, or DENYNONE */
/* depending on access, and retries LOOP_NOPEN number of times if the */
......@@ -50,7 +54,7 @@ int nopen(const char* str, uint access)
while(((file=sopen(str,access,share,DEFFILEMODE))==-1)
&& (errno==EACCES || errno==EAGAIN || errno==EDEADLOCK) && count++<LOOP_NOPEN)
if(count)
mswait(100);
SLEEP(100);
return(file);
}
......@@ -208,46 +212,3 @@ BOOL backup(const char *fname, int backup_level, BOOL ren)
return TRUE;
}
/****************************************************************************/
/* Open a log file for append, supporting log rotation based on size */
/****************************************************************************/
FILE* fopenlog(scfg_t* cfg, const char* path)
{
const int mode = O_WRONLY|O_CREAT|O_APPEND;
int file;
FILE* fp;
if((fp = fnopen(&file, path, mode)) == NULL)
return NULL;
if(cfg->max_log_size && cfg->max_logs_kept && filelength(file) >= (off_t)cfg->max_log_size) {
#ifdef _WIN32 // Can't rename an open file on Windows
fclose(fp);
#endif
backup(path, cfg->max_logs_kept, /* rename: */TRUE);
#ifndef _WIN32
fclose(fp);
#endif
if((fp = fnopen(NULL, path, mode)) == NULL)
return NULL;
}
return fp;
}
// Write to a log file and may close it if reached max size
size_t fwritelog(scfg_t* cfg, void* buf, size_t size, FILE** fp)
{
size_t result = fwrite(buf, 1, size, *fp);
if(cfg->max_log_size && ftell(*fp) >= (off_t)cfg->max_log_size) {
fclose(*fp);
*fp = NULL;
}
return result;
}
void fcloselog(FILE* fp)
{
fclose(fp);
}
......@@ -23,8 +23,8 @@
#define _NOPEN_H
#include <stdio.h> /* FILE */
#include <fcntl.h> /* O_RDONLY */
#include "gen_defs.h" /* BOOL (switch to stdbool when we stop using BCB6) */
#include "scfgdefs.h"
#ifdef __cplusplus
extern "C" {
......@@ -36,9 +36,6 @@ BOOL ftouch(const char* fname);
BOOL fmutex(const char* fname, const char* text, long max_age);
BOOL fcompare(const char* fn1, const char* fn2);
BOOL backup(const char* org, int backup_level, BOOL ren);
FILE* fopenlog(scfg_t*, const char* path);
size_t fwritelog(scfg_t*, void* buf, size_t size, FILE**);
void fcloselog(FILE*);
#ifdef __cplusplus
}
......
......@@ -1301,6 +1301,9 @@ extern "C" {
,const char* host, union xp_sockaddr* addr);
DLLEXPORT BOOL spamlog(scfg_t* cfg, struct mqtt*, char* prot, char* action, char* reason
,char* host, char* ip_addr, char* to, char* from);
DLLEXPORT FILE* fopenlog(scfg_t*, const char* path);
DLLEXPORT size_t fwritelog(scfg_t*, void* buf, size_t size, FILE**);
DLLEXPORT void fcloselog(FILE*);
/* data.cpp */
DLLEXPORT time_t getnextevent(scfg_t* cfg, event_t* event);
......
......@@ -24,7 +24,7 @@
#include <time.h>
#include "gen_defs.h" /* uchar, ushort, uint, ulong, etc. */
#include "smbdefs.h"
#include "nodedefs.h" /* node_t */
#include "fidodefs.h" /* fmsghdr_t, fpkthdr_t, FIDO_*, etc. */
#include "xpbeep.h" /* BEEP() */
......@@ -47,8 +47,6 @@
#define Y2K_2DIGIT_WINDOW 70
#define FNOPEN_BUF_SIZE (2*1024)
#define MAX_FILENAME_LEN 64
#define MAX_FILEEXT_LEN 15
#define ILLEGAL_FILENAME_CHARS "\\/|<>:\";,%?*"
......@@ -511,7 +509,6 @@ typedef enum { /* Values for xtrn_t.event */
#define SEC_CID 10 /* Ten second pause for caller ID */
#define SEC_RING 6 /* Maximum seconds between rings */
#define LOOP_NOPEN 50 /* Retries before file access denied */
#define LOOP_NODEDAB 50 /* Retries on node.dab locking/unlocking */
/* String lengths */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment