Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libdss/dssmagic.c
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 2002-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#pragma prototyped
21
/*
22
* dss generic magic number support
23
*
24
* Glenn Fowler
25
* AT&T Research
26
*/
27
28
#include "dsslib.h"
29
30
#include <magicid.h>
31
32
ssize_t
33
dssmagic(Dss_t* dss, Sfio_t* sp, const char* name, const char* type, uint32_t version, size_t size)
34
{
35
Magicid_t magic;
36
ssize_t n;
37
38
memset(&magic, 0, sizeof(magic));
39
magic.magic = MAGICID;
40
if (!name)
41
name = dss->id;
42
strncopy(magic.name, name, sizeof(magic.name));
43
strncopy(magic.type, type, sizeof(magic.type));
44
magic.version = version;
45
magic.size = size;
46
sfwrite(sp, &magic, sizeof(magic));
47
while (size < sizeof(magic))
48
size += magic.size;
49
for (n = size; size > sizeof(magic); size--)
50
sfputc(sp, 0);
51
if (sferror(sp))
52
{
53
if (dss->disc->errorf)
54
(*dss->disc->errorf)(dss, dss->disc, ERROR_SYSTEM|2, "magic header write error");
55
return -1;
56
}
57
return n;
58
}
59
60