/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 2002-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* *18***********************************************************************/19#pragma prototyped20/*21* dss generic magic number support22*23* Glenn Fowler24* AT&T Research25*/2627#include "dsslib.h"2829#include <magicid.h>3031ssize_t32dssmagic(Dss_t* dss, Sfio_t* sp, const char* name, const char* type, uint32_t version, size_t size)33{34Magicid_t magic;35ssize_t n;3637memset(&magic, 0, sizeof(magic));38magic.magic = MAGICID;39if (!name)40name = dss->id;41strncopy(magic.name, name, sizeof(magic.name));42strncopy(magic.type, type, sizeof(magic.type));43magic.version = version;44magic.size = size;45sfwrite(sp, &magic, sizeof(magic));46while (size < sizeof(magic))47size += magic.size;48for (n = size; size > sizeof(magic); size--)49sfputc(sp, 0);50if (sferror(sp))51{52if (dss->disc->errorf)53(*dss->disc->errorf)(dss, dss->disc, ERROR_SYSTEM|2, "magic header write error");54return -1;55}56return n;57}585960