Changeset 5832:f0b38d5ea016 in roaraudio


Ignore:
Timestamp:
01/06/13 16:15:56 (8 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added roar_libroar_get_path_static() and make use of it

Files:
9 edited

Legend:

Unmodified
Added
Removed
  • include/libroar/config.h

    r5828 r5832  
    181181char * roar_libroar_get_path(const char * name, int null_as_universal, const char * product, const char * provider) _LIBROAR_ATTR_USE_RESULT; 
    182182 
     183// This is similar roar_libroar_get_path() with the following diffrences: 
     184// * No product, provider or universal attribute can be passed. 
     185//   The result is as if they were 0, NULL, NULL. 
     186// * The returned buffer is some read-only memory which does not need to be 
     187//   freed. 
     188const char * roar_libroar_get_path_static(const char * name); 
     189 
    183190// list all known paths: 
    184191ssize_t roar_libroar_list_path(const char ** list, size_t len, size_t offset) _LIBROAR_ATTR_USE_RESULT _LIBROAR_ATTR_NONNULL_ALL; 
  • libroar/basic.c

    r5823 r5832  
    108108     dup2(socks[1], ROAR_STDIN ); 
    109109     dup2(socks[1], ROAR_STDOUT); 
    110      execl("/bin/sh", "/bin/sh", "-c", daemonimage, (_LIBROAR_GOOD_CAST char*)NULL); 
     110     execl(roar_libroar_get_path_static("bin-sh"), roar_libroar_get_path_static("bin-sh"), "-c", daemonimage, (_LIBROAR_GOOD_CAST char*)NULL); 
    111111     execlp("sh", "sh", "-c", daemonimage, (_LIBROAR_GOOD_CAST char*)NULL); 
    112112    break; 
     
    321321 
    322322#if !defined(ROAR_TARGET_WIN32) && !defined(ROAR_TARGET_MICROCONTROLLER) 
    323  if ( (server == NULL || *server == 0) && (i = readlink("/etc/roarserver", user_sock, sizeof(user_sock)-1)) != -1 ) { 
     323 if ( (server == NULL || *server == 0) && (i = readlink(roar_libroar_get_path_static("sysconf-roarserver"), user_sock, sizeof(user_sock)-1)) != -1 ) { 
    324324   user_sock[i] = 0; 
    325325   server = user_sock; 
     
    352352#if !defined(ROAR_TARGET_WIN32) && !defined(ROAR_TARGET_MICROCONTROLLER) 
    353353   if ( (pwd = getpwuid(getuid())) == NULL ) { 
    354     roar_server = "/NX-HOME-DIR"; 
     354    roar_server = roar_libroar_get_path_static("dir-nx-home"); 
    355355   } else { 
    356356    roar_server = pwd->pw_dir; 
  • libroar/cdrom.c

    r5823 r5832  
    9191 close(fh[1]); 
    9292 
    93  execl(ROAR_HAVE_BIN_CDPARANOIA, "cdparanoia", "--force-cdrom-device", "/dev/stdin", "-q", 
     93 execl(roar_libroar_get_path_static("bin-cdparanoia"), roar_libroar_get_path_static("bin-cdparanoia"), "--force-cdrom-device", roar_libroar_get_path_static("dev-stdin"), "-q", 
    9494                ROAR_CDROM_CDPARANOIA_OUTPUTFORMAT, pos, "-", NULL); 
    9595 
  • libroar/config.c

    r5831 r5832  
    436436} 
    437437 
    438 static const struct { 
     438static const struct pathinfo { 
    439439 const char * name; 
    440440 const char * path; 
     
    487487 {"bin-pinentry",       ROAR_HAVE_BIN_PINENTRY, 0, 0}, 
    488488 {"bin-ssh_askpass",    ROAR_HAVE_BIN_SSH_ASKPASS, 0, 0}, 
    489  {"bin-gtk_led_askpass", ROAR_HAVE_BIN_GTK_LED_ASKPASS, 0, 0}, 
    490  {"bin-x11_ssh_askpass", ROAR_HAVE_BIN_X11_SSH_ASKPASS, 0, 0}, 
    491  {"bin-gnome_ssh_askpass", ROAR_HAVE_BIN_GNOME_SSH_ASKPASS, 0, 0}, 
     489 {"bin-gtk-led-askpass", ROAR_HAVE_BIN_GTK_LED_ASKPASS, 0, 0}, 
     490 {"bin-x11-ssh-askpass", ROAR_HAVE_BIN_X11_SSH_ASKPASS, 0, 0}, 
     491 {"bin-gnome-ssh-askpass", ROAR_HAVE_BIN_GNOME_SSH_ASKPASS, 0, 0}, 
    492492 {"bin-gpg",            ROAR_HAVE_BIN_GPG, 0, 0}, 
    493493 {"bin-eject",          ROAR_HAVE_BIN_EJECT, 0, 0}, 
    494494 
    495495 // devices: 
    496  {"dev-stdin",          ROAR_PREFIX_DEV "/stdin", 0, 0}, 
     496 {"dev-stdin",                  ROAR_PREFIX_DEV "/stdin", 0, 0}, 
    497497 {"dev-default-pwmled",         ROAR_PREFIX_DEV "/ttyS0", 0, 0}, 
     498 {"dev-default-dmx4linux",      ROAR_PREFIX_DEV "/dmx", 0, 0}, 
    498499 
    499500#ifdef ROAR_DEFAULT_CDROM 
     
    512513 // proc: 
    513514#ifdef ROAR_PROC_NET_DECNET 
    514  {"proc-net-decnet",     ROAR_PROC_NET_DECNET, 0, 0}, 
     515 {"proc-net-decnet",            ROAR_PROC_NET_DECNET, 0, 0}, 
    515516#endif 
    516517#ifdef ROAR_PROC_NET_DECNET_NEIGH 
    517  {"proc-net-decnet-neigh", ROAR_PROC_NET_DECNET_NEIGH, 0, 0}, 
     518 {"proc-net-decnet-neigh",      ROAR_PROC_NET_DECNET_NEIGH, 0, 0}, 
    518519#endif 
    519520#ifdef ROAR_PROC_NET_ARP 
    520  {"proc-net-arp",        ROAR_PROC_NET_ARP, 0, 0}, 
     521 {"proc-net-arp",               ROAR_PROC_NET_ARP, 0, 0}, 
    521522#endif 
    522523 
    523524 // sysconf: 
    524  {"sysconf-hosts",       ROAR_PREFIX_SYSCONF "/hosts", 0, 0}, 
    525  {"sysconf-roarserver",  ROAR_PREFIX_SYSCONF "/roarserver", 0, 0}, 
     525 {"sysconf-hosts",              ROAR_PREFIX_SYSCONF "/hosts", 0, 0}, 
     526 {"sysconf-roarserver",         ROAR_PREFIX_SYSCONF "/roarserver", 0, 0}, 
    526527 
    527528 // special dirs: 
    528  {"dir-nx-home",         "/NX-HOME-DIR", 0, 0} 
     529 {"dir-nx-home",                "/NX-HOME-DIR", 0, 0} 
    529530}; 
    530531 
     
    606607} 
    607608 
     609static const struct pathinfo * __lookup_path(const char * name) { 
     610 size_t i; 
     611 
     612 if ( name == NULL ) { 
     613  roar_err_set(ROAR_ERROR_FAULT); 
     614  return NULL; 
     615 } 
     616 
     617 for (i = 0; i < (sizeof(__paths)/sizeof(*__paths)); i++) 
     618  if ( !strcmp(__paths[i].name, name) ) 
     619   return &(__paths[i]); 
     620 
     621 roar_err_set(ROAR_ERROR_NOENT); 
     622 return NULL; 
     623} 
     624 
    608625char * roar_libroar_get_path(const char * name, int null_as_universal, const char * product, const char * provider) { 
     626 const struct pathinfo * path; 
    609627 char buf_product[384]; 
    610628 char buf_provider[384]; 
    611629 ssize_t len_prefix, len_product, len_provider; 
    612  size_t i; 
    613630 char * ret, * p; 
    614631 
    615632 ROAR_DBG("roar_libroar_get_path(name='%s', null_as_universal=%i, product='%s', provider='%s') = ?", name, null_as_universal, product, provider); 
    616633 
    617  if ( name == NULL ) { 
    618   roar_err_set(ROAR_ERROR_FAULT); 
    619   return NULL; 
    620  } 
    621  
    622  for (i = 0; i < (sizeof(__paths)/sizeof(*__paths)); i++) { 
    623   if ( !!strcmp(__paths[i].name, name) ) 
    624    continue; 
    625  
    626   if ( ((null_as_universal || product != NULL) && !__paths[i].with_product) || 
    627        (provider != NULL && !__paths[i].with_provider) ) { 
    628    roar_err_set(ROAR_ERROR_INVAL); 
    629    return NULL; 
    630   } 
    631  
    632   if ( __product2path(buf_product, sizeof(buf_product), null_as_universal, product, __paths[i].with_product) == -1 ) 
    633    return NULL; 
    634  
    635   if ( __provider2path(buf_provider, sizeof(buf_provider), provider) == -1 ) 
    636    return NULL; 
    637  
    638   len_prefix = roar_mm_strlen(__paths[i].path); 
    639   len_product = roar_mm_strlen(buf_product); 
    640   len_provider = roar_mm_strlen(buf_provider); 
    641  
    642   p = ret = roar_mm_malloc(len_prefix+len_product+len_provider+1); 
    643   if ( ret == NULL ) 
    644    return NULL; 
    645  
    646   memcpy(p, __paths[i].path, len_prefix); 
    647   p += len_prefix; 
    648   if ( p[-1] == '/' ) 
    649    p--; 
    650   memcpy(p, buf_product, len_product); 
    651   p += len_product; 
    652   memcpy(p, buf_provider, len_provider); 
    653   p += len_provider; 
    654  
    655   *p = 0; 
    656  
    657   return ret; 
    658  } 
    659  
    660  roar_err_set(ROAR_ERROR_NOENT); 
    661  return NULL; 
     634 path = __lookup_path(name); 
     635 if ( path == NULL ) 
     636  return NULL; 
     637 
     638 if ( ((null_as_universal || product != NULL) && !path->with_product) || 
     639      (provider != NULL && !path->with_provider) ) { 
     640  roar_err_set(ROAR_ERROR_INVAL); 
     641  return NULL; 
     642 } 
     643 
     644 if ( __product2path(buf_product, sizeof(buf_product), null_as_universal, product, path->with_product) == -1 ) 
     645  return NULL; 
     646 
     647 if ( __provider2path(buf_provider, sizeof(buf_provider), provider) == -1 ) 
     648  return NULL; 
     649 
     650 len_prefix = roar_mm_strlen(path->path); 
     651 len_product = roar_mm_strlen(buf_product); 
     652 len_provider = roar_mm_strlen(buf_provider); 
     653 
     654 p = ret = roar_mm_malloc(len_prefix+len_product+len_provider+1); 
     655 if ( ret == NULL ) 
     656  return NULL; 
     657 
     658 memcpy(p, path->path, len_prefix); 
     659 p += len_prefix; 
     660 if ( p[-1] == '/' ) 
     661  p--; 
     662 memcpy(p, buf_product, len_product); 
     663 p += len_product; 
     664 memcpy(p, buf_provider, len_provider); 
     665 p += len_provider; 
     666 
     667 *p = 0; 
     668 
     669 return ret; 
     670} 
     671 
     672const char * roar_libroar_get_path_static(const char * name) { 
     673 const struct pathinfo * path; 
     674 
     675 path = __lookup_path(name); 
     676 if ( path == NULL ) 
     677  return NULL; 
     678 
     679 return path->path; 
    662680} 
    663681 
  • libroar/enumdev.c

    r5823 r5832  
    145145 
    146146#if !defined(ROAR_TARGET_WIN32) && !defined(ROAR_TARGET_MICROCONTROLLER) 
    147   if ( (i = readlink("/etc/roarserver", buf, sizeof(buf)-1)) != -1 ) { 
     147  if ( (i = readlink(roar_libroar_get_path_static("sysconf-roarserver"), buf, sizeof(buf)-1)) != -1 ) { 
    148148    buf[i] = 0; 
    149149    _add(buf); 
     
    230230  {ROAR_PROC_NET_ARP, NULL, 1}, 
    231231#endif 
    232 //  {"/etc/hosts", NULL, 0}, 
     232//  {roar_libroar_get_path_static("sysconf-hosts"), NULL, 0}, 
    233233  {NULL, NULL, 0} 
    234234 }; 
  • libroar/pinentry.c

    r5823 r5832  
    112112     ROAR_U_EXIT(1); 
    113113 
    114     execlp(ROAR_HAVE_BIN_PINENTRY, "RoarAudio", "--display", display, "--ttytype", term, "--ttyname", tty, NULL); 
     114    execlp(roar_libroar_get_path_static("bin-pinentry"), "RoarAudio", "--display", display, "--ttytype", term, "--ttyname", tty, NULL); 
    115115 
    116116    ROAR_U_EXIT(1); 
  • libroar/socket.c

    r5823 r5832  
    11641164 ROAR_DBG("roar_socket_open_ssh(*): proxy_port=%i, user='%s', proxy_addr='%s'", proxy_port, user, proxy_addr); 
    11651165 ROAR_DBG("roar_socket_open_ssh(*): rcmd: %s", rcmd); 
    1166  snprintf(cmd, 1023, ROAR_HAVE_BIN_SSH " -p %i -l '%s' '%s' '%s'", proxy_port, user, proxy_addr, rcmd); 
     1166 snprintf(cmd, 1023, "%s -p %i -l '%s' '%s' '%s'", roar_libroar_get_path_static("bin-ssh"), proxy_port, user, proxy_addr, rcmd); 
    11671167 cmd[1023] = 0; 
    11681168 
  • libroar/vio_cmd.c

    r5823 r5832  
    185185     ROAR_U_EXIT(1); 
    186186 
    187     execlp("/bin/sh", "/bin/sh", "-c", child->cmd, (_LIBROAR_GOOD_CAST char*)NULL); 
     187    execlp(roar_libroar_get_path_static("bin-sh"), roar_libroar_get_path_static("bin-sh"), "-c", child->cmd, (_LIBROAR_GOOD_CAST char*)NULL); 
    188188 
    189189    ROAR_U_EXIT(1); 
     
    644644   return -1; 
    645645 
    646   snprintf(command, 1024, "%s --batch --no-verbose --quiet --passphrase-repeat 0 --passphrase-fd %i %s %s", ROAR_HAVE_BIN_GPG, pwpipe[0], para, opts); 
     646  snprintf(command, 1024, "%s --batch --no-verbose --quiet --passphrase-repeat 0 --passphrase-fd %i %s %s", roar_libroar_get_path_static("bin-gpg"), pwpipe[0], para, opts); 
    647647 
    648648  write(pwpipe[1], pw, strlen(pw)); 
     
    650650  close(pwpipe[1]); 
    651651 } else { 
    652   snprintf(command, 1024, "%s --no-verbose --quiet %s %s", ROAR_HAVE_BIN_GPG, para, opts); 
     652  snprintf(command, 1024, "%s --no-verbose --quiet %s %s", roar_libroar_get_path_static("bin-gpg"), para, opts); 
    653653 } 
    654654 
  • roard/driver_dmx.c

    r5823 r5832  
    4747 
    4848  if ( dev == NULL ) 
    49    dev = "/dev/dmx"; 
     49   dev = roar_libroar_get_path_static("dev-default-dmx4linux"); 
    5050 
    5151  if ( roar_vio_open_dstr(vio, dev, &def, 1) == -1 ) { 
Note: See TracChangeset for help on using the changeset viewer.