summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
authorGreg Ercolano <erco@seriss.com>2020-07-21 20:15:41 -0700
committerGreg Ercolano <erco@seriss.com>2020-08-01 14:19:40 -0700
commit2141c63628a831d3f53dad7035c94028f8d0d629 (patch)
tree614cb7b627da2decbb7cfe49c081f9d7b4140c58 /src/drivers
parent7514a73ba759f7fc9965eeef3b92ece899bd7a69 (diff)
Implement + deploy fl_strdup()
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/Android/Fl_Android_Application.cxx3
-rw-r--r--src/drivers/Android/Fl_Android_System_Driver.H3
-rw-r--r--src/drivers/Android/Fl_Android_System_Driver.cxx3
-rw-r--r--src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm3
-rw-r--r--src/drivers/GDI/Fl_GDI_Graphics_Driver_font.cxx9
-rw-r--r--src/drivers/Posix/Fl_Posix_System_Driver.H2
-rw-r--r--src/drivers/Posix/Fl_Posix_System_Driver.cxx3
-rw-r--r--src/drivers/PostScript/Fl_PostScript.cxx3
-rw-r--r--src/drivers/Quartz/Fl_Quartz_Graphics_Driver_font.cxx5
-rw-r--r--src/drivers/SVG/Fl_SVG_File_Surface.cxx12
-rw-r--r--src/drivers/WinAPI/Fl_WinAPI_System_Driver.H3
-rw-r--r--src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx3
-rw-r--r--src/drivers/X11/Fl_X11_System_Driver.cxx3
-rw-r--r--src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_x.cxx5
-rw-r--r--src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx11
15 files changed, 45 insertions, 26 deletions
diff --git a/src/drivers/Android/Fl_Android_Application.cxx b/src/drivers/Android/Fl_Android_Application.cxx
index 87053543a..793ebb5a1 100644
--- a/src/drivers/Android/Fl_Android_Application.cxx
+++ b/src/drivers/Android/Fl_Android_Application.cxx
@@ -25,6 +25,7 @@
#include <FL/platform.H>
#include <FL/fl_draw.H>
+#include <FL/fl_string.h>
#include <jni.h>
@@ -376,7 +377,7 @@ void *Fl_Android_Application::thread_entry(void* param)
pthread_cond_broadcast(&pCond);
pthread_mutex_unlock(&pMutex);
- char *argv[] = { strdup(pActivity->obbPath), 0 };
+ char *argv[] = { fl_strdup(pActivity->obbPath), 0 };
main(1, argv);
destroy();
diff --git a/src/drivers/Android/Fl_Android_System_Driver.H b/src/drivers/Android/Fl_Android_System_Driver.H
index 198d7a2b3..84f8262a4 100644
--- a/src/drivers/Android/Fl_Android_System_Driver.H
+++ b/src/drivers/Android/Fl_Android_System_Driver.H
@@ -22,6 +22,7 @@
#ifndef FL_ANDROID_SYSTEM_DRIVER_H
#define FL_ANDROID_SYSTEM_DRIVER_H
+#include <FL/fl_string.h>
#include "../../Fl_System_Driver.H"
#include <stdarg.h>
@@ -46,7 +47,7 @@ public:
virtual void fatal(const char *format, va_list args);
virtual char *utf2mbcs(const char *s);
virtual char *getenv(const char *var);
- virtual int putenv(const char *var) { return ::putenv(strdup(var)); }
+ virtual int putenv(const char *var) { return ::putenv(fl_strdup(var)); }
virtual int open(const char *fnam, int oflags, int pmode);
virtual int open_ext(const char *fnam, int binary, int oflags, int pmode);
virtual FILE *fopen(const char *fnam, const char *mode);
diff --git a/src/drivers/Android/Fl_Android_System_Driver.cxx b/src/drivers/Android/Fl_Android_System_Driver.cxx
index 0fa9671c5..d25e96425 100644
--- a/src/drivers/Android/Fl_Android_System_Driver.cxx
+++ b/src/drivers/Android/Fl_Android_System_Driver.cxx
@@ -18,6 +18,7 @@
#include "Fl_Android_System_Driver.H"
#include <FL/Fl.H>
#include <FL/fl_utf8.h>
+#include <FL/fl_string.h>
#include <FL/filename.H>
#include <FL/Fl_File_Browser.H>
#include <FL/Fl_File_Icon.H>
@@ -545,7 +546,7 @@ Fl_WinAPI_System_Driver::filename_relative(char *to, // O - Relative filename
char *newslash; // Directory separator
const char *slash; // Directory separator
char *cwd = 0L, *cwd_buf = 0L;
- if (base) cwd = cwd_buf = strdup(base);
+ if (base) cwd = cwd_buf = fl_strdup(base);
// return if "from" is not an absolute path
if (from[0] == '\0' ||
diff --git a/src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm b/src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm
index ab3d90fb0..2a0955622 100644
--- a/src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm
+++ b/src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm
@@ -26,6 +26,7 @@
#include <FL/platform.H>
#include <FL/fl_ask.H>
#include <FL/fl_draw.H>
+#include <FL/fl_string.h>
#import <Cocoa/Cocoa.h>
typedef OSStatus (*PMSessionSetDocumentFormatGeneration_type)(
@@ -196,7 +197,7 @@ int Fl_Cocoa_Printer_Driver::begin_job (int pagecount, int *frompage, int *topag
if (perr_message) {
NSError *nserr = [NSError errorWithDomain:NSCocoaErrorDomain code:status userInfo:nil];
NSString *s = [nserr localizedDescription];
- if (s) *perr_message = strdup([s UTF8String]);
+ if (s) *perr_message = fl_strdup([s UTF8String]);
}
return 2;
}
diff --git a/src/drivers/GDI/Fl_GDI_Graphics_Driver_font.cxx b/src/drivers/GDI/Fl_GDI_Graphics_Driver_font.cxx
index 1e2b492f3..3371c4e08 100644
--- a/src/drivers/GDI/Fl_GDI_Graphics_Driver_font.cxx
+++ b/src/drivers/GDI/Fl_GDI_Graphics_Driver_font.cxx
@@ -41,6 +41,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <FL/fl_string.h>
// This function fills in the FLTK font table with all the fonts that
// are found on the X server. It tries to place the fonts into families
@@ -98,12 +99,12 @@ enumcbw(CONST LOGFONTW *lpelf,
if (!strcmp(Fl::get_font_name((Fl_Font)i),n)) {free(n);return 1;}
char buffer[LF_FACESIZE + 1];
strcpy(buffer+1, n);
- buffer[0] = ' '; Fl::set_font((Fl_Font)(fl_free_font++), strdup(buffer));
+ buffer[0] = ' '; Fl::set_font((Fl_Font)(fl_free_font++), fl_strdup(buffer));
if (lpelf->lfWeight <= 400)
- buffer[0] = 'B', Fl::set_font((Fl_Font)(fl_free_font++), strdup(buffer));
- buffer[0] = 'I'; Fl::set_font((Fl_Font)(fl_free_font++), strdup(buffer));
+ buffer[0] = 'B', Fl::set_font((Fl_Font)(fl_free_font++), fl_strdup(buffer));
+ buffer[0] = 'I'; Fl::set_font((Fl_Font)(fl_free_font++), fl_strdup(buffer));
if (lpelf->lfWeight <= 400)
- buffer[0] = 'P', Fl::set_font((Fl_Font)(fl_free_font++), strdup(buffer));
+ buffer[0] = 'P', Fl::set_font((Fl_Font)(fl_free_font++), fl_strdup(buffer));
free(n);
return 1;
} /* enumcbw */
diff --git a/src/drivers/Posix/Fl_Posix_System_Driver.H b/src/drivers/Posix/Fl_Posix_System_Driver.H
index 55255b83f..3f4cf72c8 100644
--- a/src/drivers/Posix/Fl_Posix_System_Driver.H
+++ b/src/drivers/Posix/Fl_Posix_System_Driver.H
@@ -38,6 +38,7 @@
- directory and file access
- system time and system timer
- multithreading
+ - string management
*/
class Fl_Posix_System_Driver : public Fl_System_Driver
@@ -74,6 +75,7 @@ public:
virtual const char *home_directory_name() { return ::getenv("HOME"); }
virtual int dot_file_hidden() {return 1;}
virtual void gettime(time_t *sec, int *usec);
+ virtual char* strdup(const char *s) {return ::strdup(s);}
};
#endif // FL_POSIX_SYSTEM_DRIVER_H
diff --git a/src/drivers/Posix/Fl_Posix_System_Driver.cxx b/src/drivers/Posix/Fl_Posix_System_Driver.cxx
index d39ea6c82..9f255f3d0 100644
--- a/src/drivers/Posix/Fl_Posix_System_Driver.cxx
+++ b/src/drivers/Posix/Fl_Posix_System_Driver.cxx
@@ -20,6 +20,7 @@
#include <FL/Fl_File_Browser.H>
#include <FL/Fl_File_Icon.H>
#include <FL/filename.H>
+#include <FL/fl_string.h>
#include <FL/Fl.H>
#include <locale.h>
#include <stdio.h>
@@ -65,7 +66,7 @@ void *Fl_Posix_System_Driver::dlopen(const char *filename)
ptr = double_dlopen(filename);
# ifdef __APPLE_CC__ // allows testing on Darwin + XQuartz + fink
if (!ptr) {
- char *f_dylib = strdup(filename);
+ char *f_dylib = fl_strdup(filename);
strcpy(strrchr(f_dylib, '.'), ".dylib");
char path[FL_PATH_MAX];
sprintf(path, "/sw/lib/%s", f_dylib);
diff --git a/src/drivers/PostScript/Fl_PostScript.cxx b/src/drivers/PostScript/Fl_PostScript.cxx
index b7b10da8e..5adf20562 100644
--- a/src/drivers/PostScript/Fl_PostScript.cxx
+++ b/src/drivers/PostScript/Fl_PostScript.cxx
@@ -23,6 +23,7 @@
#include <FL/Fl_PostScript.H>
#include <FL/Fl_Native_File_Chooser.H>
#include "../../Fl_System_Driver.H"
+#include <FL/fl_string.h>
#include <stdarg.h>
#include <time.h>
@@ -83,7 +84,7 @@ int Fl_PostScript_File_Device::begin_job (int pagecount, enum Fl_Paged_Device::P
Fl_PostScript_Graphics_Driver *ps = driver();
ps->output = fl_fopen(fnfc.filename(), "w");
if(ps->output == NULL) return 2;
- ps->ps_filename_ = strdup(fnfc.filename());
+ ps->ps_filename_ = fl_strdup(fnfc.filename());
ps->start_postscript(pagecount, format, layout);
this->set_current();
return 0;
diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_font.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_font.cxx
index e6352af2a..fe43f0c6c 100644
--- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_font.cxx
+++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_font.cxx
@@ -79,6 +79,7 @@
#include <FL/Fl.H>
#include <FL/platform.H>
#include <FL/fl_utf8.h> // for fl_utf8toUtf16()
+#include <FL/fl_string.h> // fl_strdup()
Fl_Fontdesc* fl_fonts = NULL;
@@ -682,7 +683,7 @@ Fl_Font Fl_Quartz_Graphics_Driver::ADD_SUFFIX(set_fonts, _CoreText)(const char*
CFRelease(font);
static char fname[200];
CFStringGetCString(cfname, fname, sizeof(fname), kCFStringEncodingUTF8);
- tabfontnames[i] = strdup(fname); // never free'ed
+ tabfontnames[i] = fl_strdup(fname); // never free'ed
CFRelease(cfname);
}
CFRelease(arrayref);
@@ -869,7 +870,7 @@ Fl_Font Fl_Quartz_Graphics_Driver::ADD_SUFFIX(set_fonts, _ATSU)(const char* xsta
oName[511] = 0;
else
oName[actualLength] = 0;
- Fl::set_font((Fl_Font)(fl_free_font++), strdup(oName));
+ Fl::set_font((Fl_Font)(fl_free_font++), fl_strdup(oName));
// free(oName);
}
free(oFontIDs);
diff --git a/src/drivers/SVG/Fl_SVG_File_Surface.cxx b/src/drivers/SVG/Fl_SVG_File_Surface.cxx
index d0946da8b..5106c6486 100644
--- a/src/drivers/SVG/Fl_SVG_File_Surface.cxx
+++ b/src/drivers/SVG/Fl_SVG_File_Surface.cxx
@@ -28,6 +28,8 @@
#include <FL/Fl_RGB_Image.H>
#include <FL/Fl_Pixmap.H>
#include <FL/Fl_Bitmap.H>
+#include <FL/fl_string.h>
+
extern "C" {
#if defined(HAVE_LIBPNG)
# ifdef HAVE_PNG_H
@@ -137,7 +139,7 @@ Fl_SVG_Graphics_Driver::Fl_SVG_Graphics_Driver(FILE *f) {
clip_count_ = 0;
clip_ = NULL;
user_dash_array_ = 0;
- dasharray_ = strdup("none");
+ dasharray_ = fl_strdup("none");
p_size = 0;
p = NULL;
last_rgb_name_ = NULL;
@@ -205,13 +207,13 @@ void Fl_SVG_Graphics_Driver::compute_dasharray(float s, char *dashes) {
sprintf(dasharray_+strlen(dasharray_), "%.3f,", (*p)/s);
}
dasharray_[strlen(dasharray_) - 1] = 0;
- if (user_dash_array_ != dashes) user_dash_array_ = strdup(dashes);
+ if (user_dash_array_ != dashes) user_dash_array_ = fl_strdup(dashes);
return;
}
int dash_part = line_style_ & 0xFF;
if (dash_part == FL_SOLID) {
if (dasharray_ && strcmp(dasharray_, "none")) free(dasharray_);
- dasharray_ = strdup("none");
+ dasharray_ = fl_strdup("none");
} else {
int cap_part = (line_style_ & 0xF00);
bool is_flat = (cap_part == FL_CAP_FLAT || cap_part == 0);
@@ -458,7 +460,7 @@ void Fl_SVG_Graphics_Driver::define_rgb_png(Fl_RGB_Image *rgb, const char *name,
}
if (name) {
if (last_rgb_name_) free(last_rgb_name_);
- last_rgb_name_ = strdup(name);
+ last_rgb_name_ = fl_strdup(name);
}
float f = rgb->data_w() > rgb->data_h() ? float(rgb->w()) / rgb->data_w(): float(rgb->h()) / rgb->data_h();
if (name) fprintf(out_, "<defs><image id=\"%s\" ", name);
@@ -547,7 +549,7 @@ static void term_destination(jpeg_compress_struct *cinfo) {
void Fl_SVG_Graphics_Driver::define_rgb_jpeg(Fl_RGB_Image *rgb, const char *name, int x, int y) {
if (name) {
if (last_rgb_name_) free(last_rgb_name_);
- last_rgb_name_ = strdup(name);
+ last_rgb_name_ = fl_strdup(name);
}
float f = rgb->data_w() > rgb->data_h() ? float(rgb->w()) / rgb->data_w(): float(rgb->h()) / rgb->data_h();
if (name) fprintf(out_, "<defs><image id=\"%s\" ", name);
diff --git a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H
index 91b230d5f..049e6c114 100644
--- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H
+++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H
@@ -24,6 +24,7 @@
#include "../../Fl_System_Driver.H"
#include <stdarg.h>
+#include <string.h> // strdup
/*
Move everything here that manages the system interface.
@@ -34,6 +35,7 @@
- directory and file access
- system time and system timer
- multithreading
+ - string management
*/
class Fl_WinAPI_System_Driver : public Fl_System_Driver
@@ -116,6 +118,7 @@ public:
virtual void remove_fd(int, int when);
virtual void remove_fd(int);
virtual void gettime(time_t *sec, int *usec);
+ virtual char* strdup(const char *s) { return ::_strdup(s); }
};
#endif // FL_WINAPI_SYSTEM_DRIVER_H
diff --git a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx
index 592e192e3..d37ec62ff 100644
--- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx
+++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx
@@ -18,6 +18,7 @@
#include "Fl_WinAPI_System_Driver.H"
#include <FL/Fl.H>
#include <FL/fl_utf8.h>
+#include <FL/fl_string.h> // fl_strdup()
#include <FL/filename.H>
#include <FL/Fl_File_Browser.H>
#include <FL/Fl_File_Icon.H>
@@ -548,7 +549,7 @@ Fl_WinAPI_System_Driver::filename_relative(char *to, // O - Relative filename
char *newslash; // Directory separator
const char *slash; // Directory separator
char *cwd = 0L, *cwd_buf = 0L;
- if (base) cwd = cwd_buf = strdup(base);
+ if (base) cwd = cwd_buf = fl_strdup(base);
// return if "from" is not an absolute path
if (from[0] == '\0' ||
diff --git a/src/drivers/X11/Fl_X11_System_Driver.cxx b/src/drivers/X11/Fl_X11_System_Driver.cxx
index 28827bcfc..8a308bdb8 100644
--- a/src/drivers/X11/Fl_X11_System_Driver.cxx
+++ b/src/drivers/X11/Fl_X11_System_Driver.cxx
@@ -17,6 +17,7 @@
#include "Fl_X11_System_Driver.H"
#include <FL/Fl_File_Browser.H>
+#include <FL/fl_string.h> // fl_strdup
#include "../../flstring.h"
#include <X11/Xlib.h>
@@ -592,7 +593,7 @@ bool Fl_X11_System_Driver::probe_for_GTK(int major, int minor, void **ptr_gtk) {
char *before = NULL;
// record in "before" the calling program's current locale
char *p = setlocale(LC_ALL, NULL);
- if (p) before = strdup(p);
+ if (p) before = fl_strdup(p);
int ac = 0;
init_f(&ac, NULL); // may change the locale
if (before) {
diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_x.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_x.cxx
index 8b3784566..9251eafe4 100644
--- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_x.cxx
+++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_x.cxx
@@ -20,6 +20,7 @@
#include <FL/Fl.H>
#include <FL/fl_draw.H>
#include <FL/platform.H>
+#include <FL/fl_string.h>
#include "Fl_Font.H"
#include <stdio.h>
@@ -305,7 +306,7 @@ Fl_Font Fl_Xlib_Graphics_Driver::set_fonts(const char* xstarname) {
if (fl_fonts[j].name && !strcmp(fl_fonts[j].name, p)) break;
} else */{
j = fl_free_font++;
- if (p == canon) p = strdup(p); else used_xlist = 1;
+ if (p == canon) p = fl_strdup(p); else used_xlist = 1;
Fl::set_font((Fl_Font)j, p);
break;
}
@@ -521,7 +522,7 @@ static char *put_font_size(const char *n, int size)
const char *f;
char *name;
int nbf = 1;
- name = strdup(n);
+ name = fl_strdup(n);
while (name[i]) {
if (name[i] == ',') {nbf++; name[i] = '\0';}
i++;
diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx
index 5a80904ab..6b42b880a 100644
--- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx
+++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx
@@ -20,6 +20,7 @@
#include "Fl_Xlib_Graphics_Driver.H"
#include <FL/Fl.H>
#include <FL/fl_draw.H>
+#include <FL/fl_string.h> // fl_strdup()
#include <FL/platform.H>
#include "Fl_Font.H"
@@ -423,7 +424,7 @@ Fl_Font Fl_Xlib_Graphics_Driver::set_fonts(const char* pattern_name)
}
else
{ // The listed name has been modified
- full_list[j] = strdup(first);
+ full_list[j] = fl_strdup(first);
// Free the font name storage
free (font);
}
@@ -451,7 +452,7 @@ Fl_Font Fl_Xlib_Graphics_Driver::set_fonts(const char* pattern_name)
make_raw_name(xft_name, full_list[j]);
// NOTE: This just adds on AFTER the default fonts - no attempt is made
// to identify already loaded fonts. Is this bad?
- stored_name = strdup(xft_name);
+ stored_name = fl_strdup(xft_name);
Fl::set_font((Fl_Font)(j + FL_FREE_FONT), stored_name);
fl_free_font ++;
@@ -552,7 +553,7 @@ static XftFont* fontopen(const char* name, /*Fl_Fontsize*/double size, bool core
}
if(comma_count) { // multiple comma-separated names were passed
- char *local_name = strdup(name); // duplicate the full name so we can edit the copy
+ char *local_name = fl_strdup(name); // duplicate the full name so we can edit the copy
char *curr = local_name; // points to first name in string
char *nxt; // next name in string
do {
@@ -681,7 +682,7 @@ static XftFont* fontopen(const char* name, /*Fl_Fontsize*/double size, bool core
* XLFD's to construct a "super-pattern" that incorporates attributes from all
* XLFD's and use that to perform a XftFontMatch(). Maybe...
*/
- char *local_name = strdup(name);
+ char *local_name = fl_strdup(name);
if(comma_count) { // This means we were passed multiple XLFD's
char *pc = strchr(local_name, ',');
*pc = 0; // terminate the XLFD at the first comma
@@ -1087,7 +1088,7 @@ static XFontStruct* load_xfont_for_xft2(Fl_Graphics_Driver *driver) {
const char *weight = wt_med; // no specifc weight requested - accept any
char slant = 'r'; // regular non-italic by default
char xlfd[128]; // we will put our synthetic XLFD in here
- char *pc = strdup(fl_fonts[fnum].name); // what font were we asked for?
+ char *pc = fl_strdup(fl_fonts[fnum].name); // what font were we asked for?
#if USE_PANGO
char *p = pc + 1;
while (*p) { *p = tolower(*p); p++; }