Sisyphus repository
Last update: 1 october 2023 | SRPMs: 18631 | Visits: 37501262
en ru br
ALT Linux repos
S:0.2-alt2
5.0: 0.1-alt1
4.1: 0.1-alt1
4.0: 0.1-alt1

Group :: System/Libraries
RPM: libzmalloc

 Main   Changelog   Spec   Patches   Sources   Download   Gear   Bugs and FR  Repocop 

libzmalloc-0.2/000075500000000000000000000000001201442300500134705ustar00rootroot00000000000000libzmalloc-0.2/Makefile000064400000000000000000000016641201442300500151370ustar00rootroot00000000000000LIBRARY = libzmalloc
VERSION=0.1
MAJOR = 0

SHAREDLIB = $(LIBRARY).so
SONAME = $(SHAREDLIB).$(MAJOR)

INSTALL = install

LIBDIR = $(libdir)

CC=gcc
CFLAGS =$(FLAGS) -I../include $(RPM_OPT_FLAGS)
LINK.o = $(CC) $(LDFLAGS) $(FLAGS) $(TARGET_ARCH)

LIB_SRC = zmalloc.c

LIB_SOBJ = $(LIB_SRC:%.c=%.so)

.PHONY: all install clean

all: $(SHAREDLIB)

install: all
$(INSTALL) -pD -m755 $(SHAREDLIB) $(libdir)/$(SHAREDLIB).$(VERSION)
@ln -sf $(SHAREDLIB).$(VERSION) $(libdir)/$(SONAME)
@ln -sf $(SONAME) $(libdir)/$(SHAREDLIB)
$(INSTALL) -pD -m755 zmalloc-ctrl $(bindir)/zmalloc-ctrl
$(INSTALL) -pD -m755 zmalloc-enable $(bindir)/zmalloc-enable
$(INSTALL) -pD -m755 zmalloc-disable $(bindir)/zmalloc-disable

clean:
$(RM) $(LIB_SOBJ) $(SHAREDLIB) $(SONAME) core *~ test

$(SHAREDLIB): $(LIB_SOBJ)
$(LINK.o) -shared -Wl,-soname,$(SONAME) $+ $(OUTPUT_OPTION)
ln -sf $(SHAREDLIB) $(SONAME)

%.so: %.c
$(CC) -c $(CPPFLAGS) -fpic $< $(OUTPUT_OPTION)
libzmalloc-0.2/test1.c000064400000000000000000000005731201442300500147010ustar00rootroot00000000000000#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#define SIZE 100

print_memory(char *c,int size)
{
int i;
for(i=0;i<size;i++){
printf(" %.2x",*(c+i));
if ((i+1) % 20 == 0) puts("");
}
puts("");
}

int main(void)
{
char *l=(char*)malloc(SIZE);

if (l)
print_memory(l,SIZE);
else
puts("unable to malloc memory");

return 0;
}
libzmalloc-0.2/test2.c000064400000000000000000000010111201442300500146660ustar00rootroot00000000000000#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#define SIZE 100

print_memory(char *c,int size)
{
int i;
for(i=0;i<size;i++){
printf(" %.2x",*(c+i));
if ((i+1) % 20 == 0) puts("");
}
puts("");
}


int main()
{
char *c;

c=malloc(SIZE*sizeof(char));
memset(c,0x33,SIZE*sizeof(char));
puts("old memory content:");
print_memory(c,SIZE);

free(c);
c=malloc(SIZE*sizeof(char));

puts("new memory content:");
print_memory(c,SIZE);

return 0;
}

libzmalloc-0.2/zmalloc-ctrl000075500000000000000000000071661201442300500160330ustar00rootroot00000000000000#!/bin/sh
# Copyright (C) 2012 Andrew V. Stepanov <stanv@altlinux.org>
#
# The zmalloc utility for the libzmalloc project
#
# This file 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 2 of the License, or
# (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#


# Require libshell
. shell-error
. shell-quote
. shell-config
. shell-var
. shell-args


# Backcall for libshell
show_help()
{
cat <<EOF
$PROG - control libzmalloc.

Usage: $PROG [options]

Options:
-e, --enable enable libzmalloc in system;
-d, --disable disable libzmalloc in system;
-s, --status shows current status libzmalloc (ret: 0 - enabled, 1 - disabled);
-q, --quiet try to be more quiet;
-v, --verbose print a message for each action;
-V, --version print program version and exit;
-h, --help show this text and exit.

Report bugs to http://bugs.altlinux.ru/

EOF
exit
}


# Backcall for libshell
print_version()
{
local prog
prog="$1" && shift
cat <<EOF
$prog version 0.2
Written by Andrew V. Stepanov <stanv@altlinux.org>

Copyright (C) 2012 Andrew V. Stepanov <stanv@altlinux.org>
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
EOF
exit
}


CONFIG="/etc/ld.so.preload"


# Test zmalloc is enabled
# Return 0 if enabled, otherwise 1
zmalloc_test() {
if grep -qs '^/lib/libzmalloc\.so\.0\.1$' "$CONFIG"; then
return
fi

return 1
}


# Enable zmalloc
zmalloc_enable() {
if zmalloc_test; then
fatal "libzmalloc is already enabled in system."
fi

if ! [ -w "$(dirname $CONFIG)" ]; then
fatal "Can't write $CONFIG."
fi

echo '/lib/libzmalloc.so.0.1' >> "$CONFIG" && /sbin/ldconfig
test -z "$quiet" && message "libzmalloc now enabled."

exit
}


# Disable zmalloc
zmalloc_disable() {
if ! zmalloc_test; then
fatal "libzmalloc is already disabled in system."
fi

if ! [ -f "$CONFIG" -a -w "$CONFIG" ]; then
fatal "Can't write $CONFIG."
fi

sed '\,^/lib/libzmalloc.so.0.1$, d' -i "$CONFIG" && /sbin/ldconfig
test -z "$quiet" && message "libzmalloc now disabled."

exit
}


# Status zmalloc
zmalloc_status() {
local ret=

if zmalloc_test; then
test -z "$quiet" && message "libzmalloc enabled."
ret=0
else
test -z "$quiet" && message "libzmalloc disabled."
ret=1
fi

exit $ret
}


TEMP=`getopt -n $PROG -o e,d,s,$getopt_common_opts -l enable,disable,status,$getopt_common_longopts -- "$@"` ||
show_usage
eval set -- "$TEMP"

status= disable= enable=

while :; do
case "$1" in
-s|--status) status="yes"
;;
-d|--disable) disable="yes"
;;
-e|--enable) enable="yes"
;;
--) shift; break
;;
*) parse_common_option "$1"
;;
esac
shift
done

test -n "$status" && zmalloc_status
test -n "$disable" && zmalloc_disable
test -n "$enable" && zmalloc_enable

show_usage 'Insufficient arguments.'

# vim: autoindent tabstop=2 shiftwidth=2 expandtab softtabstop=2 filetype=sh
libzmalloc-0.2/zmalloc-disable000075500000000000000000000001271201442300500164600ustar00rootroot00000000000000#!/bin/sh

sed '\,^/lib/libzmalloc.so.0.1$, d' -i /etc/ld.so.preload && /sbin/ldconfig
libzmalloc-0.2/zmalloc-enable000075500000000000000000000002371201442300500163050ustar00rootroot00000000000000#!/bin/sh

if ! grep -qs '^/lib/libzmalloc\.so\.0.1$' /etc/ld.so.preload; then
echo '/lib/libzmalloc.so.0.1' >>/etc/ld.so.preload &&
/sbin/ldconfig
fi
libzmalloc-0.2/zmalloc.c000064400000000000000000000002631201442300500152760ustar00rootroot00000000000000#define _GNU_SOURCE 1
#include <stdio.h>
#include <dlfcn.h>
#include <stdlib.h>

void *malloc(size_t size){
return calloc(1,size);
}

void free(void *ptr){
cfree(ptr);
}
 
design & coding: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
current maintainer: Michael Shigorin