ARPDAS_QNX6 1.0
|
00001 /* tm_dev_name.c provides a general-purpose approach to finding other 00002 */ 00003 #include <stdlib.h> 00004 #include <string.h> 00005 #include <limits.h> 00006 #include "company.h" 00007 #include "nortlib.h" 00008 #include "tm.h" 00009 #include "nl_assert.h" 00010 00011 /** \brief Build a standard name for QNX6 resource 00012 00013 <code>#include "tm.h"<br> 00014 const char *tm_dev_name(const char *base);</code> 00015 00016 If the input base string does not start with a '/', 00017 tm_dev_name() builds a string of the form: 00018 /dev/huarp/exp/base where exp is the current value of the 00019 environment variable "Experiment" and base is the input 00020 argument string. This is the standard means of building 00021 resource names within the ARP Data Acquisition System 00022 architecture. 00023 00024 Returns a pointer to a static buffer containing the expanded name. 00025 You must save the string if it is needed for long. 00026 00027 @return the input string if it begins with a '/'. Otherwise 00028 returns a pointer to a static buffer containing the expanded 00029 name. 00030 */ 00031 const char *tm_dev_name(const char *base) { 00032 static char name[PATH_MAX]; 00033 char *exp; 00034 int nb; 00035 00036 assert(base != NULL); 00037 if ( base[0] == '/' ) return base; 00038 exp = getenv("Experiment"); 00039 if (exp == NULL) exp = "none"; 00040 nb = snprintf( name, PATH_MAX, "/dev/%s/%s/%s", COMPANY, exp, base ); 00041 if ( nb >= PATH_MAX ) { 00042 if (nl_response) 00043 nl_error(nl_response, "Constructed name for %s is too long", base); 00044 return(NULL); 00045 } 00046 return name; 00047 }