Serialisation Support Functions
John Walker
-
-
- Version $Id$
*/
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2011 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
This program is Free Software; you can redistribute it and/or
- modify it under the terms of version two of the GNU General Public
+ modify it under the terms of version three of the GNU Affero General Public
License as published by the Free Software Foundation and included
in the file LICENSE.
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
- You should have received a copy of the GNU General Public License
+ You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- Bacula® is a registered trademark of John Walker.
+ Bacula® is a registered trademark of Kern Sibbald.
The licensor of Bacula is the Free Software Foundation Europe
(FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
Switzerland, email:ftf@fsfeurope.org.
void serial_int64(uint8_t * * const ptr, const int64_t v)
{
- if (htonl(1) == 1L) {
+ if (bigendian()) {
memcpy(*ptr, &v, sizeof(int64_t));
} else {
int i;
void serial_uint64(uint8_t * * const ptr, const uint64_t v)
{
- if (htonl(1) == 1L) {
+ if (bigendian()) {
memcpy(*ptr, &v, sizeof(uint64_t));
} else {
int i;
void serial_btime(uint8_t * * const ptr, const btime_t v)
{
- if (htonl(1) == 1L) {
+ if (bigendian()) {
memcpy(*ptr, &v, sizeof(btime_t));
} else {
int i;
void serial_float64(uint8_t * * const ptr, const float64_t v)
{
- if (htonl(1) == 1L) {
+ if (bigendian()) {
memcpy(*ptr, &v, sizeof(float64_t));
} else {
int i;
void serial_string(uint8_t * * const ptr, const char * const str)
{
- int len = strlen(str) + 1;
-
- memcpy(*ptr, str, len);
- *ptr += len;
+ int i;
+ char *dest = (char *)*ptr;
+ char *src = (char *)str;
+ for (i=0; src[i] != 0; i++) {
+ dest[i] = src[i];
+ }
+ dest[i++] = 0; /* terminate output string */
+ *ptr += i; /* update pointer */
+// Dmsg2(000, "ser src=%s dest=%s\n", src, dest);
}
{
uint64_t v;
- if (htonl(1) == 1L) {
+ if (bigendian()) {
memcpy(&v, *ptr, sizeof(uint64_t));
} else {
int i;
{
btime_t v;
- if (htonl(1) == 1L) {
+ if (bigendian()) {
memcpy(&v, *ptr, sizeof(btime_t));
} else {
int i;
{
float64_t v;
- if (htonl(1) == 1L) {
+ if (bigendian()) {
memcpy(&v, *ptr, sizeof(float64_t));
} else {
int i;
return v;
}
-void unserial_string(uint8_t * * const ptr, char * const str)
+void unserial_string(uint8_t * * const ptr, char * const str, int max)
{
- int len = strlen((char *) *ptr) + 1;
- memcpy(str, (char *) *ptr, len);
- *ptr += len;
+ int i;
+ char *src = (char*)(*ptr);
+ char *dest = str;
+ for (i=0; i<max && src[i] != 0; i++) {
+ dest[i] = src[i];
+ }
+ dest[i++] = 0; /* terminate output string */
+ *ptr += i; /* update pointer */
+// Dmsg2(000, "unser src=%s dest=%s\n", src, dest);
}