ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Urlader/urlader.c
(Generate patch)

Comparing Urlader/urlader.c (file contents):
Revision 1.12 by root, Fri Jan 6 07:56:36 2012 UTC vs.
Revision 1.14 by root, Mon Feb 6 21:57:48 2012 UTC

1/*
2 * Copyright (c) 2012 Marc Alexander Lehmann <schmorp@schmorp.de>
3 *
4 * Redistribution and use in source and binary forms, with or without modifica-
5 * tion, are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
16 * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
17 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-
18 * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH-
22 * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
23 * OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * the GNU General Public License ("GPL") version 2 or any later version,
27 * in which case the provisions of the GPL are applicable instead of
28 * the above. If you wish to allow the use of your version of this file
29 * only under the terms of the GPL and not to allow others to use your
30 * version of this file under the BSD license, indicate your decision
31 * by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL. If you do not delete the
33 * provisions above, a recipient may use your version of this file under
34 * either the BSD or the GPL.
35 */
36
1#include "urlib.h" 37#include "urlib.h"
2#include "urlib.c" 38#include "urlib.c"
3 39
4#include <stdio.h> 40#include <stdio.h>
5#include <stdlib.h> 41#include <stdlib.h>
350#else 386#else
351 387
352int 388int
353main (int argc, char *argv[]) 389main (int argc, char *argv[])
354{ 390{
355 u_setenv ("URLADER_EXEPATH", argv [0]);
356
357 pack_handle = u_open (argv [0]);
358 if (!u_valid (pack_handle))
359 u_fatal ("unable to open executable pack");
360
361 if (!getcwd (currdir, sizeof (currdir))) 391 if (!getcwd (currdir, sizeof (currdir)))
362 strcpy (currdir, "."); 392 strcpy (currdir, ".");
363 393
394 {
395 const char *exe_path = 0;
396
397 if (strchr (argv [0], '/'))
398 exe_path = argv [0];
399 else
400 {
401 const char *p, *path = getenv ("PATH");
402
403 if (!path)
404 u_fatal ("unable to find executable, try running with full path.");
405
406 for (p = path; ; )
407 {
408 const char *e = p;
409 int l;
410
411 while (*e && *e != ':')
412 ++e;
413
414 l = e - p;
415 memcpy (tmppath, p, l);
416
417 if (!l)
418 tmppath [l++] = '.';
419
420 tmppath [l++] = '/';
421
422 strcpy (tmppath + l, argv [0]);
423
424 if (!access (tmppath, X_OK))
425 break;
426
427 p = e;
428 if (!*p)
429 u_fatal ("unable to find executable, try running with full path.");
430
431 ++p;
432 }
433
434 exe_path = tmppath;
435 }
436
437 pack_handle = u_open (exe_path);
438 if (!u_valid (pack_handle))
439 u_fatal ("unable to open executable for reading - permissions problem?");
440
441 u_setenv ("URLADER_EXEPATH", exe_path);
442 }
443
364#if 0 444#if 0
365 /* intersperse hostname, for whatever reason */ 445 /* intersperse hostname, for whatever reason */
366 446
367 if (gethostname (tmppath, sizeof (tmppath))) 447 if (gethostname (tmppath, sizeof (tmppath)))
368 strcpy (tmppath, "default"); 448 strcpy (tmppath, "default");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines