Add pv_asprintf() and change the way the terminal lock file is stored, so it is in a dynamically allocated buffer rather than using one of a fixed size.

This commit is contained in:
Andrew Wood
2026-04-19 16:24:26 +01:00
parent a59c91f03d
commit 9f63212a7c
6 changed files with 190 additions and 30 deletions
+3 -3
View File
@@ -139,7 +139,7 @@ struct pvwatchfd_s;
typedef /*@null@*/ struct pvwatchfd_s *pvwatchfd_t;
/* String pointer, that is the only pointer to this resource, that can be null. */
typedef /*@only@*/ /*@null@*/ char * nullable_string_t;
typedef /*@only@*/ /*@null@*/ char * nullable_only_string_t;
/*
* Structure for holding PV internal state. Opaque outside the PV library.
@@ -163,7 +163,7 @@ struct pvstate_s {
* Input files *
***************/
struct pvinputfiles_s {
/*@only@*/ /*@null@*/ nullable_string_t *filename; /* input filenames */
/*@only@*/ /*@null@*/ nullable_only_string_t *filename; /* input filenames */
unsigned int file_count; /* number of input files */
} files;
@@ -370,7 +370,7 @@ struct pvstate_s {
* Cursor/IPC state *
********************/
struct pvcursorstate_s {
char lock_file[PV_SIZEOF_CRS_LOCK_FILE];
/*@only@*/ /*@null@*/ char *lock_file; /* terminal lock filename */
#ifdef HAVE_IPC
/*@keep@*/ /*@null@*/ struct pvipccursorstate_s *shared; /* data shared between instances */
int shmid; /* ID of our shared memory segment */
+16 -1
View File
@@ -98,12 +98,27 @@ extern double pv_percentage(off_t, const off_t);
* String handling wrappers.
*/
/* String pointer that can be null. */
typedef /*@null@*/ char * nullable_string_ptr;
/*
* Wrapper for sprintf(), falling back to sprintf() on systems without that
* function.
*/
extern int pv_snprintf(char *, size_t, const char *, ...);
/*
* Wrapper for snprintf(), falling back to sprintf() on systems without that
* function.
*/
extern int pv_snprintf(char *, size_t, const char *, ...);
/*
* Wrapper for asprintf(), providing an equivalent on systems without that
* function.
*/
extern int pv_asprintf(nullable_string_ptr *, const char *, ...);
/*
* Implementation of strlcat() where it is unavailable: append a string to a
* buffer, constraining the buffer to a particular size and ensuring
@@ -115,7 +130,7 @@ extern size_t pv_strlcat(char *, const char *, size_t);
* Allocate and return a duplicate of a \0-terminated string, ensuring that
* the duplicate is also \0-terminated. Returns NULL on error.
*/
/*@null@ */ /*@only@ */ extern char *pv_strdup(const char *);
/*@null@ */ /*@only@ */ extern char *pv_strdup(const /*@null@ */ char *);
/*
* Return a pointer to the last matching character in the buffer, or NULL if