00001 /* 00002 * Copyright 2008 The qDecoder Project. All rights reserved. 00003 * 00004 * Redistribution and use in source and binary forms, with or without 00005 * modification, are permitted provided that the following conditions 00006 * are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 00014 * THIS SOFTWARE IS PROVIDED BY THE QDECODER PROJECT ``AS IS'' AND ANY 00015 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00016 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00017 * DISCLAIMED. IN NO EVENT SHALL THE QDECODER PROJECT BE LIABLE FOR ANY 00018 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00019 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00020 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00021 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00022 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00023 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00024 */ 00025 00030 #include <stdio.h> 00031 #include <stdlib.h> 00032 #include <stdbool.h> 00033 #include <string.h> 00034 #include "qDecoder.h" 00035 00044 const char *qSysGetEnv(const char *envname, const char *nullstr) { 00045 const char *envstr = getenv(envname); 00046 if (envstr != NULL) return envstr; 00047 return nullstr; 00048 } 00049 00059 char *qSysCmd(const char *cmd) { 00060 FILE *fp = popen(cmd, "r"); 00061 if (fp == NULL) return NULL; 00062 char *str = qFileRead(fp, NULL); 00063 pclose(fp); 00064 00065 if(str == NULL) str = strdup(""); 00066 return str; 00067 } 00068 00074 const char *qDecoderVersion(void) { 00075 return _Q_VERSION; 00076 }