summaryrefslogtreecommitdiffstats
path: root/save.h
diff options
context:
space:
mode:
authorSuper User2007-05-06 15:54:52 +0200
committerSuper User2007-05-06 15:54:52 +0200
commit2ed0fee489c37a6e2d4473f6185ebbe3e746ac11 (patch)
treefcf232bc282c083404cfde0ce5b04236fe202c3e /save.h
parentfirst commit (diff)
downloadlcr-2ed0fee489c37a6e2d4473f6185ebbe3e746ac11.tar.gz
lcr-2ed0fee489c37a6e2d4473f6185ebbe3e746ac11.tar.xz
lcr-2ed0fee489c37a6e2d4473f6185ebbe3e746ac11.zip
only for backup, still in coding state - no compile!!!
Diffstat (limited to 'save.h')
-rw-r--r--save.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/save.h b/save.h
new file mode 100644
index 0000000..9b2d8a9
--- /dev/null
+++ b/save.h
@@ -0,0 +1,64 @@
+/*****************************************************************************\
+** **
+** PBX4Linux **
+** **
+**---------------------------------------------------------------------------**
+** Copyright: Andreas Eversberg **
+** **
+** Macros to do save string operations to avoid buffer overflows. **
+** **
+\*****************************************************************************/
+
+
+/* save strcpy/strncpy */
+
+#define SCPY(dst, src) scpy(dst, src, sizeof(dst))
+extern __inline__ void scpy(char *dst, char *src, unsigned int siz)
+{
+ strncpy(dst, src, siz);
+ dst[siz-1] = '\0';
+}
+
+/* save strcat/strncat */
+
+#define SCAT(dst, src) scat(dst, src, sizeof(dst))
+extern __inline__ void scat(char *dst, char *src, unsigned int siz)
+{
+ strncat(dst, src, siz);
+ dst[siz-1] = '\0';
+}
+
+/* save concat of a byte */
+
+#define SCCAT(dst, src) sccat(dst, src, sizeof(dst))
+extern __inline__ void sccat(char *dst, char chr, unsigned int siz)
+{
+ if (strlen(dst) < siz-1)
+ {
+ dst[strlen(dst)+1] = '\0';
+ dst[strlen(dst)] = chr;
+ }
+}
+
+/* save sprintf/snprintf */
+
+#define SPRINT(dst, fmt, arg...) sprint(dst, sizeof(dst), fmt, ## arg)
+extern __inline__ void sprint(char *dst, unsigned int siz, char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ vsnprintf(dst, siz, fmt, args);
+ dst[siz-1] = '\0';
+ va_end(args);
+}
+
+/* unsave */
+#define UCPY strcpy
+#define UNCPY strncpy
+#define UCAT strcat
+#define UNCAT strncat
+#define UPRINT sprintf
+#define UNPRINT snprintf
+#define VUNPRINT vsnprintf
+