~ubuntu-branches/ubuntu/oneiric/irssi/oneiric

« back to all changes in this revision

Viewing changes to src/lib-popt/findme.c

  • Committer: Bazaar Package Importer
  • Author(s): Andres Rodriguez
  • Date: 2009-05-05 15:50:50 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090505155050-aoqlnpes7che9rtd
Tags: 0.8.13-1ubuntu1
* Merge from debian unstable (LP: #372411), remaining changes:
  - debian/patches: 03firsttimer_text
    + Adapt it so it tells you about connecting to irc.ubuntu.com and
      joining #ubuntu instead of irc.debian.org and #debian.
  - debian/patches: 90irc-ubuntu-com
* Fixed debian/patches/90irc-ubuntu-com for new irssi.conf.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING
2
 
   file accompanying popt source distributions, available from 
3
 
   ftp://ftp.redhat.com/pub/code/popt */
4
 
 
5
 
#include "common.h"
6
 
 
7
 
#ifdef __NeXT
8
 
/* access macros are not declared in non posix mode in unistd.h -
9
 
 don't try to use posix on NeXTstep 3.3 ! */ 
10
 
#include <libc.h>
11
 
#endif
12
 
 
13
 
#include "findme.h"
14
 
 
15
 
char * findProgramPath(char * argv0) {
16
 
    char * path = getenv("PATH");
17
 
    char * pathbuf;
18
 
    char * start, * chptr;
19
 
    char * buf;
20
 
 
21
 
    /* If there is a / in the argv[0], it has to be an absolute
22
 
       path */
23
 
    if (strchr(argv0, '/'))
24
 
        return g_strdup(argv0);
25
 
 
26
 
    if (!path) return NULL;
27
 
 
28
 
    start = pathbuf = g_strdup(path);
29
 
    buf = g_malloc(strlen(path) + strlen(argv0) + 2);
30
 
 
31
 
    chptr = NULL;
32
 
    do {
33
 
        if ((chptr = strchr(start, ':')))
34
 
            *chptr = '\0';
35
 
        sprintf(buf, "%s/%s", start, argv0);
36
 
 
37
 
#ifndef WIN32
38
 
        if (!access(buf, X_OK)) {
39
 
            g_free(pathbuf);
40
 
            return buf;
41
 
        }
42
 
#endif
43
 
 
44
 
        if (chptr) 
45
 
            start = chptr + 1;
46
 
        else
47
 
            start = NULL;
48
 
    } while (start && *start);
49
 
 
50
 
    g_free(pathbuf);
51
 
    free(buf);
52
 
 
53
 
    return NULL;
54
 
}