summaryrefslogtreecommitdiff
path: root/wrapper/rvs.h
diff options
context:
space:
mode:
Diffstat (limited to 'wrapper/rvs.h')
-rw-r--r--wrapper/rvs.h55
1 files changed, 36 insertions, 19 deletions
diff --git a/wrapper/rvs.h b/wrapper/rvs.h
index 447b533..bf8c1f5 100644
--- a/wrapper/rvs.h
+++ b/wrapper/rvs.h
@@ -1,4 +1,6 @@
-/* Copyright (C) 2009 Luke Shumaker
+/* wrapper/rvs.h -- rvs program header, contains most system-dependand code,
+ and general-purose functions.
+ Copyright (C) 2009 Luke Shumaker
This file is part of rvs.
@@ -21,19 +23,27 @@
#define FILE_rvs_h_SEEN
#include <stdio.h>
-#include <dirent.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <error.h>
+/* glibc */
extern char *program_invocation_name;
+extern char *program_invocation_short_name;
+
+/* stdlib.h */
+/*extern int EXIT_SUCCESS;*/
+/*extern int EXIT_FAILURE;*/
void *
xmalloc (size_t size)
{
void *value = malloc (size);
+ #ifdef DEBUG_ALLOC
+ printf("x=%p\n",value);
+ #endif
if (value == NULL) {
perror(program_invocation_name);
exit(EXIT_FAILURE);
@@ -45,6 +55,9 @@ void *
xrealloc (void *ptr, size_t size)
{
void *value = realloc (ptr, size);
+ #ifdef DEBUG_ALLOC
+ printf("x/%p -> %p\n",ptr,value);
+ #endif
if (value == NULL) {
perror(program_invocation_name);
exit(EXIT_FAILURE);
@@ -55,15 +68,17 @@ xrealloc (void *ptr, size_t size)
void
xfree (void *ptr)
{
- free (ptr);
+ if (ptr!=NULL)
+ #ifdef DEBUG_ALLOC
+ printf("x-%p\n",ptr);
+ #endif
+ free (ptr);
}
+/* unistd.h */
int
xchdir (const char *filename)
{
- #ifdef DEBUG
- puts (filename);
- #endif
int ret=chdir(filename);
if (ret != 0) {
error(EXIT_FAILURE,errno,"%s/",filename);
@@ -71,6 +86,7 @@ xchdir (const char *filename)
return ret;
}
+/* stdio.h */
FILE *
xfopen (const char *filename, const char *opentype)
{
@@ -83,17 +99,7 @@ xfopen (const char *filename, const char *opentype)
return file;
}
-DIR *
-xopendir (const char *dirname)
-{
- DIR *dir = opendir (dirname);
- if (dir == NULL) {
- error(EXIT_FAILURE,errno,"%s/",dirname);
- }
-
- return dir;
-}
-
+/* string funtions */
void
stradds(size_t *size, char **dest, char *str)
{
@@ -105,12 +111,23 @@ stradds(size_t *size, char **dest, char *str)
strcat(*dest, str);
}
}
-
+size_t
+xstrlen (const char *s)
+{
+ printf("xstrlen(%p)\n",s);
+ size_t size=0;
+ while (s[size] != '\0') {
+ printf("%i = %p `%c'\n",size,&s[size],s[size]);
+ size++;
+ }
+ return size;
+}
char *
stralloc (const char *string)
{
- char *copy = (char *)xmalloc(strlen(string)+1);
+ char *copy = (char *)xmalloc(xstrlen(string)+1);
strcpy(copy,string);
+ puts(copy);
return copy;
}