Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Per Cederqvist
lyskom-server-ceder-1616-generations-topgit
Commits
8607514a
Commit
8607514a
authored
Jul 08, 1998
by
Per Cederqvist
Browse files
Removed unused files.
parent
addffdeb
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/libraries/libmisc/zmalloc.c
deleted
100644 → 0
View file @
addffdeb
/*
* $Id: zmalloc.c,v 1.14 1998/07/08 13:41:37 ceder Exp $
* Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
*
* LysKOM is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 1, or (at your option)
* any later version.
*
* LysKOM is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of 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
* along with LysKOM; see the file COPYING. If not, write to
* Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
* or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
* MA 02139, USA.
*
* Please mail bug reports to bug-lyskom@lysator.liu.se.
*/
/*
* zmalloc.c
*
*
*
* Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Lysator Computer Club,
* Linkoping University, Sweden
*
* Everyone is granted permission to copy, modify and redistribute
* this code, provided the people they give it to can.
*
*
* Author: Thomas Bellman
* Lysator Computer Club
* Linkoping University
* Sweden
*
* email: Bellman@Lysator.LiU.SE
*
*
* Any opinions expressed in this code are the author's PERSONAL opinions,
* and does NOT, repeat NOT, represent any official standpoint of Lysator,
* even if so stated.
*/
static
const
char
*
rcsid
=
"$Id: zmalloc.c,v 1.14 1998/07/08 13:41:37 ceder Exp $"
;
#include
<sys/types.h>
#ifdef HAVE_STDDEF_H
# include <stddef.h>
#endif
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#if STDC_HEADERS || HAVE_STRING_H
# include <string.h>
# if !STDC_HEADERS && HAVE_MEMORY_H
# include <memory.h>
# endif
#else
/* not STDC_HEADERS and not HAVE_STRING_H */
# include <strings.h>
/* memory.h and strings.h conflict on some systems. */
#endif
/* not STDC_HEADERS and not HAVE_STRING_H */
#ifndef NULL
# include <stdio.h>
#endif
#include
"compiler.h"
#include
"zmalloc.h"
#include
"rcs.h"
USE
(
rcsid
);
#define EXPORT
typedef
struct
{
int
refcount
;
size_t
size
;
}
z_info
;
#define REFCOUNT(pointer) \
(((z_info *) ((char *) pointer - sizeof (z_info)))->refcount)
#define AREA_SIZE(pointer) \
(((z_info *) ((char *) pointer - sizeof (z_info)))->size)
#define MIN(n1, n2) (((n1) < (n2)) ? (n1) : (n2))
EXPORT
void
*
zmalloc
(
size_t
size
)
{
void
*
memory
;
memory
=
malloc
(
size
+
sizeof
(
z_info
));
if
(
memory
==
NULL
)
return
NULL
;
((
z_info
*
)
memory
)
->
size
=
size
;
((
z_info
*
)
memory
)
->
refcount
=
1
;
return
(
char
*
)
memory
+
sizeof
(
z_info
);
}
EXPORT
void
*
zcalloc
(
size_t
n
,
size_t
size
)
{
void
*
memory
;
memory
=
malloc
(
n
*
size
+
sizeof
(
z_info
));
if
(
memory
==
NULL
)
return
NULL
;
((
z_info
*
)
memory
)
->
size
=
n
*
size
;
((
z_info
*
)
memory
)
->
refcount
=
1
;
memset
((
char
*
)
memory
+
sizeof
(
z_info
),
0
,
n
*
size
);
return
(
char
*
)
memory
+
sizeof
(
z_info
);
}
EXPORT
void
*
zrealloc
(
void
*
ptr
,
size_t
size
)
{
void
*
memory
;
if
(
ptr
==
NULL
)
return
zmalloc
(
size
);
if
(
REFCOUNT
(
ptr
)
>
1
)
{
memory
=
zmalloc
(
size
);
if
(
memory
==
NULL
)
return
NULL
;
memcpy
(
memory
,
ptr
,
MIN
(
size
,
AREA_SIZE
(
ptr
)));
--
REFCOUNT
(
ptr
);
return
memory
;
}
else
{
memory
=
realloc
((
char
*
)
ptr
-
sizeof
(
z_info
),
size
+
sizeof
(
z_info
));
return
(
char
*
)
memory
+
sizeof
(
z_info
);
}
}
EXPORT
void
zfree
(
void
*
ptr
)
{
if
(
ptr
!=
NULL
&&
--
REFCOUNT
(
ptr
)
<=
0
)
{
free
((
char
*
)
ptr
-
sizeof
(
z_info
));
}
}
EXPORT
void
zdestruct
(
void
*
ptr
)
{
if
(
ptr
!=
NULL
)
free
((
char
*
)
ptr
-
sizeof
(
z_info
));
}
EXPORT
void
*
zuse
(
void
*
ptr
)
{
if
(
ptr
!=
NULL
)
{
++
REFCOUNT
(
ptr
);
}
return
ptr
;
}
EXPORT
void
*
zown
(
void
*
ptr
)
{
void
*
memory
;
if
(
ptr
==
NULL
)
return
NULL
;
if
(
REFCOUNT
(
ptr
)
==
1
)
return
ptr
;
else
{
if
((
memory
=
malloc
(
AREA_SIZE
(
ptr
)))
==
NULL
)
return
NULL
;
memcpy
(
memory
,
ptr
,
AREA_SIZE
(
ptr
));
zfree
(
ptr
);
return
memory
;
}
}
src/libraries/libmisc/zmalloc.h
deleted
100644 → 0
View file @
addffdeb
/*
* $Id: zmalloc.h,v 1.6 1995/01/01 20:17:17 ceder Exp $
* Copyright (C) 1990, 1991, 1993, 1994, 1995 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
*
* LysKOM is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 1, or (at your option)
* any later version.
*
* LysKOM is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of 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
* along with LysKOM; see the file COPYING. If not, write to
* Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
* or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
* MA 02139, USA.
*
* Please mail bug reports to bug-lyskom@lysator.liu.se.
*/
/*
* $Id: zmalloc.h,v 1.6 1995/01/01 20:17:17 ceder Exp $
*
* zmalloc.h -- Memory allocation routines with reference counts
*
*
* Copyright (C) 1990, 1991, 1993, 1994, 1995 Lysator Computer Club,
* Linkoping University, Sweden
*
* Everyone is granted permission to copy, modify and redistribute
* this code, provided the people they give it to can.
*
*
* Author: Thomas Bellman
* Lysator Computer Club
* Linkoping University
* Sweden
*
* email: Bellman@Lysator.LiU.SE
*/
#ifndef _ZMALLOC_H_INCLUDED__
#define _ZMALLOC_H_INCLUDED__
/*
* Allocate a piece of memory and set its reference count to 1.
* Allocating a zero sized object is allowed, and results in a
* unique pointer that can be used by all the other routines in
* this package, and must be released using zfree(), but it
* points to "nothing".
*/
extern
void
*
zmalloc
(
size_t
size
);
/*
* Allocate N contigous objects of size SIZE, set the contents
* to binary 0 and set the reference count to 1. Allocating 0
* objecs, or objects of size zero, is allowed, and results in a
* unique pointer that can be used by all the other routines in
* this package, and must be released using zfree(), but it
* points to "nothing".
*/
extern
void
*
zcalloc
(
size_t
n
,
size_t
size
);
/*
* Reallocate the storage PTR points to the size SIZE. If
* "others" are still holding references to this memory, they
* can still use it, and the caller of zrealloc() gets a copy of
* the original memory area. NULL is returned if the request
* couldn't be honored, and the memory area is still in use by
* the caller. Reallocating the NULL pointer is equivalent to
* doing a zmalloc() with the same size. The same rules for
* allocating objects of size 0 as for zmalloc() and zcalloc()
* applies.
*/
extern
void
*
zrealloc
(
void
*
ptr
,
size_t
size
);
/*
* Indicate that the memory pointed to by PTR is not used anymore
* by the caller, i e the reference count is decremented by one.
* The memory pointed to might be released as a result of this
* call. Freeing the NULL pointer is a no-op.
*/
extern
void
zfree
(
void
*
ptr
);
/*
* Free the area pointed to by PTR regardless of how many are
* referencing it. This invalidiates all pointers to the area.
* Calling zdestruct() on a NULL pointer is a no-op.
*/
extern
void
zdestruct
(
void
*
ptr
);
/*
* Add onother user of the memory pointed to by PTR, i e increase
* the reference count by one. Return value is PTR. Using the
* NULL pointer is a no-op, i e it just returns NULL.
*/
extern
void
*
zuse
(
void
*
ptr
);
/*
* Get a private copy of the area pointed to by PTR. If
* necessary, i e if others are holding references to the area,
* copies the contents to a new place, and releases the original
* area. If you want to keep a reference to the old area, you
* should do 'zown(zuse(p))'.
*/
extern
void
*
zown
(
void
*
ptr
);
#endif
/* _ZMALLOC_H_INCLUDED__ */
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment