Commit 0cb622ac authored by Per Cederqvist's avatar Per Cederqvist

Created the utility function sstrdup.

* src/server/ram-smalloc.c, src/include/server/smalloc.h:
(sstrdup): New function.
parent b7c6921e
master
dbfile_open_read-check-magic
From: Per Cederqvist <ceder@lysator.liu.se>
Subject: Check the magic cookie when opening database files.
Subject: Created the utility function sstrdup.
* src/server/ram-io.c (dbfile_open_read): New argument:
wanted_magic. Log a message and return NULL if the file contains
the wrong magic cookie. All callers updated to supply "CLEAN" as
the magic cookie.
* src/server/ram-smalloc.c, src/include/server/smalloc.h:
(sstrdup): New function.
......@@ -42,6 +42,10 @@
2010-04-01 Per Cederqvist <ceder@lysator.liu.se>
Created the utility function sstrdup.
* src/server/ram-smalloc.c, src/include/server/smalloc.h:
(sstrdup): New function.
Check the magic cookie when opening database files.
* src/server/ram-io.c (dbfile_open_read): New argument:
wanted_magic. Log a message and return NULL if the file contains
......
......@@ -44,6 +44,9 @@ extern void *
srealloc(void * ptr, size_t size); /* Never fails. It is legal to
realloc the NULL ptr. */
extern char *
sstrdup(const char *s);
/*
* Allocate temporary memory, which is automatically freed after this
* atomic call.
......
......@@ -102,6 +102,7 @@
#include <sys/types.h>
#include <assert.h>
#include <errno.h>
#include <string.h>
/* The order between inttypes.h and stdint.h is mandated by autoconf-2.57. */
#if HAVE_INTTYPES_H
# include <inttypes.h>
......@@ -377,6 +378,20 @@ srealloc(void * ptr, size_t size) /* Never fails. It is legal to */
}
char *
sstrdup(const char *s)
{
char *res;
if (s == NULL)
return NULL;
res = smalloc(strlen(s) + 1);
strcpy(res, s);
return res;
}
/*
* Allocate temporary memory, which is automatically freed after this
* atomic call.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment