Index: include/libroar/env.h
===================================================================
--- include/libroar/env.h	(revision 3958)
+++ include/libroar/env.h	(revision 3958)
@@ -0,0 +1,49 @@
+//env.h:
+
+/*
+ *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010
+ *
+ *  This file is part of libroar a part of RoarAudio,
+ *  a cross-platform sound system for both, home and professional use.
+ *  See README for details.
+ *
+ *  This file is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 3
+ *  as published by the Free Software Foundation.
+ *
+ *  libroar 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 software; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301, USA.
+ *
+ *  NOTE for everyone want's to change something and send patches:
+ *  read README and HACKING! There a addition information on
+ *  the license of this document you need to read before you send
+ *  any patches.
+ *
+ *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
+ *  or libpulse*:
+ *  The libs libroaresd, libroararts and libroarpulse link this lib
+ *  and are therefore GPL. Because of this it may be illigal to use
+ *  them with any software that uses libesd, libartsc or libpulse*.
+ */
+
+#ifndef _LIBROARENV_H_
+#define _LIBROARENV_H_
+
+#include "libroar.h"
+
+int roar_env_set(struct roar_keyval * keyval);
+const char * roar_env_get_home(int level);
+int roar_env_get_home_r(int level, char * str, size_t len);
+
+int roar_env_render_path_r(char * out, size_t len, const char * inpath);
+
+#endif
+
+//ll
Index: include/libroar/libroar.h
===================================================================
--- include/libroar/libroar.h	(revision 3805)
+++ include/libroar/libroar.h	(revision 3958)
@@ -113,4 +113,5 @@
 #include "config.h"
 #include "keyval.h"
+#include "env.h"
 #include "roardl.h"
 #include "debug.h"
Index: libroar/Makefile
===================================================================
--- libroar/Makefile	(revision 3882)
+++ libroar/Makefile	(revision 3958)
@@ -8,5 +8,5 @@
 VIO_BRIDGE=vio_bio.o vio_stdio.o
 VIO=$(VIO_META) $(VIO_BRIDGE) vio_cmd.o vio_magic.o vio_pipe.o vio_socket.o vio_winsock.o vio_stack.o vio_jumbo.o vio_proto.o vio_dstr.o vio_tantalos.o vio_rtp.o
-OBJS=libroar.o config.o debug.o error.o basic.o stream.o client.o simple.o auth.o socket.o ctl.o buffer.o meta.o file.o acl.o cdrom.o pinentry.o sshaskpass.o $(VIO) stack.o slp.o nnode.o roardl.o roarx11.o beep.o proto.o
+OBJS=libroar.o config.o debug.o error.o basic.o stream.o client.o simple.o auth.o socket.o ctl.o buffer.o meta.o file.o acl.o cdrom.o pinentry.o sshaskpass.o $(VIO) stack.o slp.o nnode.o roardl.o roarx11.o beep.o proto.o env.o
 
 #DEFINES        = -DDEBUG
Index: libroar/env.c
===================================================================
--- libroar/env.c	(revision 3958)
+++ libroar/env.c	(revision 3958)
@@ -0,0 +1,134 @@
+//env.c:
+
+/*
+ *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010
+ *
+ *  This file is part of libroar a part of RoarAudio,
+ *  a cross-platform sound system for both, home and professional use.
+ *  See README for details.
+ *
+ *  This file is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 3
+ *  as published by the Free Software Foundation.
+ *
+ *  libroar 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 software; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301, USA.
+ *
+ *  NOTE for everyone want's to change something and send patches:
+ *  read README and HACKING! There a addition information on
+ *  the license of this document you need to read before you send
+ *  any patches.
+ *
+ *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
+ *  or libpulse*:
+ *  The libs libroaresd, libroararts and libroarpulse link this lib
+ *  and are therefore GPL. Because of this it may be illigal to use
+ *  them with any software that uses libesd, libartsc or libpulse*.
+ */
+
+#include "libroar.h"
+
+int roar_env_set(struct roar_keyval * keyval);
+
+const char * roar_env_get_home(int level) {
+ const char * home = getenv("HOME");
+
+ return home;
+}
+
+int roar_env_get_home_r(int level, char * str, size_t len) {
+ size_t homelen;
+ const char * home;
+
+ if ( len == 0 )
+  return 0;
+
+ if ( str == NULL )
+  return -1;
+
+ *str = 0; // write a single termination byte to be safe...
+
+ home = roar_env_get_home(level);
+
+ if ( home == NULL )
+  return -1;
+
+ homelen = strlen(home);
+
+ if ( (len - 1) < homelen )
+  return -1;
+
+ strncpy(str, home, len);
+ str[homelen] = 0;
+
+ return 0;
+}
+
+int roar_env_render_path_r(char * out, size_t len, const char * inpath) {
+ size_t inlen;
+ size_t needlen = 0;
+ size_t homelen = 0;
+ const char * home;
+ enum { UNKNOWN, COPY, HOME } mode = UNKNOWN;
+
+ if ( len == 0 && inpath == NULL )
+  return 0;
+
+ if ( inpath == NULL )
+  return -1;
+
+ inlen = strlen(inpath);
+
+ if ( len == 0 && inlen == 0 )
+  return 0;
+
+ if ( len == 0 )
+  return -1;
+
+ if ( out == NULL )
+  return -1;
+
+ home = roar_env_get_home(0);
+
+ if ( home != NULL )
+  homelen = strlen(home);
+
+ if ( inpath[0] == '/' ) {
+  needlen = inlen;
+  mode    = COPY;
+ } else if ( inpath[0] == '~' && inpath[1] == '/' ) {
+  if ( homelen == 0 ) /* we don't know our $HOME */
+   return -1;
+
+  needlen = inlen + homelen - 1;
+  mode    = HOME;
+ }
+
+ if ( len < (needlen + 1) )
+  return -1;
+
+ switch (mode) {
+  case COPY:
+    strncpy(out, inpath, len);
+    out[len-1] = 0;
+   break;
+  case HOME:
+    strcpy(out, home);
+    strcat(out, inpath+1); // strip only ~, so we have the / if home is not /-terminated.
+   break;
+  default:
+    return -1;
+   break;
+ }
+
+ return 0;
+}
+
+//ll
