|
Packit Service |
09cdfc |
/*
|
|
Packit Service |
09cdfc |
Unix SMB/CIFS implementation.
|
|
Packit Service |
09cdfc |
Easy management of byte-length data
|
|
Packit Service |
09cdfc |
Copyright (C) Andrew Tridgell 2001
|
|
Packit Service |
09cdfc |
Copyright (C) Andrew Bartlett 2001
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
This program is free software; you can redistribute it and/or modify
|
|
Packit Service |
09cdfc |
it under the terms of the GNU General Public License as published by
|
|
Packit Service |
09cdfc |
the Free Software Foundation; either version 3 of the License, or
|
|
Packit Service |
09cdfc |
(at your option) any later version.
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
This program is distributed in the hope that it will be useful,
|
|
Packit Service |
09cdfc |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
09cdfc |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
09cdfc |
GNU General Public License for more details.
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
You should have received a copy of the GNU General Public License
|
|
Packit Service |
09cdfc |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
Packit Service |
09cdfc |
*/
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
#include <string.h>
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
#include "data_blob.h"
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
#ifndef ZERO_STRUCT
|
|
Packit Service |
09cdfc |
#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
|
|
Packit Service |
09cdfc |
#endif
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
const DATA_BLOB data_blob_null = { NULL, 0 };
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
/**
|
|
Packit Service |
09cdfc |
* @file
|
|
Packit Service |
09cdfc |
* @brief Manipulation of arbitrary data blobs
|
|
Packit Service |
09cdfc |
**/
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
/**
|
|
Packit Service |
09cdfc |
construct a data blob, must be freed with data_blob_free()
|
|
Packit Service |
09cdfc |
you can pass NULL for p and get a blank data blob
|
|
Packit Service |
09cdfc |
**/
|
|
Packit Service |
09cdfc |
DATA_BLOB data_blob_named(const void *p, size_t length, const char *name)
|
|
Packit Service |
09cdfc |
{
|
|
Packit Service |
09cdfc |
DATA_BLOB ret;
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
if (p == NULL && length == 0) {
|
|
Packit Service |
09cdfc |
ZERO_STRUCT(ret);
|
|
Packit Service |
09cdfc |
return ret;
|
|
Packit Service |
09cdfc |
}
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
if (p) {
|
|
Packit Service |
09cdfc |
ret.data = (uint8_t *)talloc_memdup(NULL, p, length);
|
|
Packit Service |
09cdfc |
} else {
|
|
Packit Service |
09cdfc |
ret.data = talloc_array(NULL, uint8_t, length);
|
|
Packit Service |
09cdfc |
}
|
|
Packit Service |
09cdfc |
if (ret.data == NULL) {
|
|
Packit Service |
09cdfc |
ret.length = 0;
|
|
Packit Service |
09cdfc |
return ret;
|
|
Packit Service |
09cdfc |
}
|
|
Packit Service |
09cdfc |
talloc_set_name_const(ret.data, name);
|
|
Packit Service |
09cdfc |
ret.length = length;
|
|
Packit Service |
09cdfc |
return ret;
|
|
Packit Service |
09cdfc |
}
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
/**
|
|
Packit Service |
09cdfc |
construct a data blob, using supplied TALLOC_CTX
|
|
Packit Service |
09cdfc |
**/
|
|
Packit Service |
09cdfc |
DATA_BLOB data_blob_talloc_named(TALLOC_CTX *mem_ctx, const void *p, size_t length, const char *name)
|
|
Packit Service |
09cdfc |
{
|
|
Packit Service |
09cdfc |
DATA_BLOB ret = data_blob_named(p, length, name);
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
if (ret.data) {
|
|
Packit Service |
09cdfc |
talloc_steal(mem_ctx, ret.data);
|
|
Packit Service |
09cdfc |
}
|
|
Packit Service |
09cdfc |
return ret;
|
|
Packit Service |
09cdfc |
}
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
/**
|
|
Packit Service |
09cdfc |
free a data blob
|
|
Packit Service |
09cdfc |
**/
|
|
Packit Service |
09cdfc |
void data_blob_free(DATA_BLOB *d)
|
|
Packit Service |
09cdfc |
{
|
|
Packit Service |
09cdfc |
if (d) {
|
|
Packit Service |
09cdfc |
talloc_free(d->data);
|
|
Packit Service |
09cdfc |
d->data = NULL;
|
|
Packit Service |
09cdfc |
d->length = 0;
|
|
Packit Service |
09cdfc |
}
|
|
Packit Service |
09cdfc |
}
|
|
Packit Service |
09cdfc |
|