Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Use realpath(3) to get canonical dream file name

  • Loading branch information...
commit 7e4d75bf51bb3f34c24678622b842c54ca951618 1 parent 01ee27f
Nick Gasson authored

Showing 4 changed files with 19 additions and 13 deletions. Show diff stats Hide diff stats

  1. +3 0  ChangeLog
  2. +6 0 config.h.in
  3. +2 2 configure.ac
  4. +8 11 src/xcowsay.c
3  ChangeLog
@@ -5,6 +5,9 @@
5 5 * src/bubblegen.c (bubble_content_left): Align left-handed text
6 6 content correctly.
7 7
  8 + * src/xcowsay.c (main): Fix bug with absolute dream image
  9 + paths. Use realpath(3) to get canonical path.
  10 +
8 11 2010-10-23 Nick Gasson <nick@nickg.me.uk>
9 12
10 13 * src/bubblegen.c (bubble_init): Add a function to generate
6 config.h.in
@@ -40,6 +40,9 @@
40 40 /* Define to 1 if you have the <libintl.h> header file. */
41 41 #undef HAVE_LIBINTL_H
42 42
  43 +/* Define to 1 if you have the <limits.h> header file. */
  44 +#undef HAVE_LIMITS_H
  45 +
43 46 /* Define to 1 if you have the <locale.h> header file. */
44 47 #undef HAVE_LOCALE_H
45 48
@@ -50,6 +53,9 @@
50 53 /* Define to 1 if you have the <memory.h> header file. */
51 54 #undef HAVE_MEMORY_H
52 55
  56 +/* Define to 1 if you have the `realpath' function. */
  57 +#undef HAVE_REALPATH
  58 +
53 59 /* Define to 1 if you have the `setlocale' function. */
54 60 #undef HAVE_SETLOCALE
55 61
4 configure.ac
@@ -17,7 +17,7 @@ AM_GNU_GETTEXT([external])
17 17
18 18 # Checks for header files.
19 19 AC_HEADER_STDC
20   -AC_CHECK_HEADERS([fcntl.h libintl.h locale.h stdlib.h string.h])
  20 +AC_CHECK_HEADERS([fcntl.h libintl.h locale.h stdlib.h string.h limits.h])
21 21
22 22 # Checks for typedefs, structures, and compiler characteristics.
23 23 AC_HEADER_STDBOOL
@@ -27,7 +27,7 @@ AC_TYPE_SIZE_T
27 27 # Checks for library functions.
28 28 AC_FUNC_MALLOC
29 29 AC_CHECK_FUNCS([strtol setlocale strcasecmp strdup strchr \
30   - getcwd strerror])
  30 + getcwd strerror realpath])
31 31
32 32 # Check for pkg-config packages
33 33 modules="gtk+-2.0 gdk-pixbuf-2.0"
19 src/xcowsay.c
@@ -26,9 +26,9 @@
26 26 #include <getopt.h>
27 27 #include <assert.h>
28 28 #include <string.h>
  29 +#include <limits.h>
29 30
30 31 #include <sys/types.h>
31   -#include <sys/stat.h>
32 32 #include <unistd.h>
33 33 #include <errno.h>
34 34
@@ -335,17 +335,14 @@ int main(int argc, char **argv)
335 335
336 336 if (dream_file != NULL) {
337 337 // Make path absolute
338   - char *wd = getcwd(NULL, 0);
339   - char *abs_path;
340   -
341   - asprintf(&abs_path, "%s/%s", wd, dream_file);
342   - free(wd);
  338 + char *abs_path = realpath(dream_file, NULL);
  339 + if (abs_path == NULL) {
  340 + perror(dream_file);
  341 + exit(EXIT_FAILURE);
  342 + }
343 343
344   - struct stat dummy;
345   - if (stat(abs_path, &dummy) != 0) {
346   - fprintf(stderr, "Error: %s: %s\n", abs_path,
347   - strerror(errno));
348   - free(abs_path);
  344 + if (access(abs_path, R_OK) != 0) {
  345 + perror(abs_path);
349 346 exit(EXIT_FAILURE);
350 347 }
351 348

0 comments on commit 7e4d75b

Please sign in to comment.
Something went wrong with that request. Please try again.