summaryrefslogtreecommitdiff
path: root/Build/source/texk/gregorio/gregorio-src/src/gregorio-utils.c
diff options
context:
space:
mode:
authorAkira Kakuto <kakuto@fuk.kindai.ac.jp>2015-12-29 23:10:03 +0000
committerAkira Kakuto <kakuto@fuk.kindai.ac.jp>2015-12-29 23:10:03 +0000
commitf281e35ba5b0fdd1bacb0f9736ba138aa42ce189 (patch)
treea9914182d36f301681c61d525eb00ffa033b7c6b /Build/source/texk/gregorio/gregorio-src/src/gregorio-utils.c
parent94b2599d4a7aece204089a48207bee187c455ec4 (diff)
gregorio 4.0.1
git-svn-id: svn://tug.org/texlive/trunk@39231 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/gregorio/gregorio-src/src/gregorio-utils.c')
-rw-r--r--Build/source/texk/gregorio/gregorio-src/src/gregorio-utils.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/Build/source/texk/gregorio/gregorio-src/src/gregorio-utils.c b/Build/source/texk/gregorio/gregorio-src/src/gregorio-utils.c
index 486dfd22e52..d6c8c0a8953 100644
--- a/Build/source/texk/gregorio/gregorio-src/src/gregorio-utils.c
+++ b/Build/source/texk/gregorio/gregorio-src/src/gregorio-utils.c
@@ -35,6 +35,7 @@
#include <string.h> /* for strcmp */
#include <locale.h>
#include <limits.h>
+#include <errno.h>
#include "struct.h"
#include "plugins.h"
#include "messages.h"
@@ -63,10 +64,10 @@ typedef enum gregorio_file_format {
/* realpath is not in mingw32 */
#ifdef _WIN32
-#ifndef PATH_MAX
-#define PATH_MAX _MAX_PATH
-#endif
-#define realpath(path,resolved_path) _fullpath(resolved_path, path, PATH_MAX)
+/* _MAX_PATH is being passed for the maxLength (third) argument of _fullpath,
+ * but we are always passing NULL for the absPath (first) argument, so it will
+ * be ignored per the MSDN documentation */
+#define realpath(path,resolved_path) _fullpath(resolved_path, path, _MAX_PATH)
#endif
/* define_path attempts to canonicalize the pathname of a given string */
@@ -130,7 +131,7 @@ static char *get_base_filename(char *fbasename)
return NULL;
}
l = strlen(fbasename) - strlen(p);
- ret = (char *) gregorio_malloc((l + 1) * sizeof(char));
+ ret = (char *) gregorio_malloc(l + 1);
gregorio_snprintf(ret, l + 1, "%s", fbasename);
ret[l] = '\0';
return ret;
@@ -141,8 +142,7 @@ static char *get_output_filename(char *fbasename, const char *extension)
{
char *output_filename = NULL;
output_filename =
- (char *) gregorio_malloc(sizeof(char) *
- (strlen(extension) + strlen(fbasename) + 2));
+ (char *) gregorio_malloc((strlen(extension) + strlen(fbasename) + 2));
output_filename = strcpy(output_filename, fbasename);
output_filename = strcat(output_filename, ".");
output_filename = strcat(output_filename, extension);
@@ -199,16 +199,22 @@ available formats are:\n\
static void check_input_clobber(char *input_file_name, char *output_file_name)
{
- char *absolute_input_file_name;
- char *absolute_output_file_name;
- char *current_directory;
- int file_cmp;
if (input_file_name && output_file_name) {
- current_directory = gregorio_malloc(PATH_MAX * sizeof(char));
- current_directory = getcwd(current_directory, PATH_MAX);
+ char *absolute_input_file_name;
+ char *absolute_output_file_name;
+ char *current_directory;
+ int file_cmp;
+ size_t bufsize = 128;
+ char *buf = gregorio_malloc(bufsize);
+ while ((current_directory = getcwd(buf, bufsize)) == NULL
+ && errno == ERANGE && bufsize < MAX_BUF_GROWTH) {
+ free(buf);
+ bufsize <<= 1;
+ buf = gregorio_malloc(bufsize);
+ }
if (current_directory == NULL) {
fprintf(stderr, _("can't determine current directory"));
- free(current_directory);
+ free(buf);
exit(1);
}
absolute_input_file_name = define_path(current_directory, input_file_name);
@@ -217,7 +223,7 @@ static void check_input_clobber(char *input_file_name, char *output_file_name)
if (file_cmp == 0) {
fprintf(stderr, "error: refusing to overwrite the input file\n");
}
- free(current_directory);
+ free(buf);
free(absolute_input_file_name);
free(absolute_output_file_name);
if (file_cmp == 0) {
@@ -239,7 +245,7 @@ static char *encode_point_and_click_filename(char *input_file_name)
}
/* 2 extra characters for a possible leading slash and final NUL */
- r = result = gregorio_malloc((strlen(filename) * 4 + 2) * sizeof(char));
+ r = result = gregorio_malloc(strlen(filename) * 4 + 2);
#ifdef _WIN32
*(r++) = '/';