OSDN Git Service

Angband 3.0.0から、my_strcpy()を移植('\0'をちゃんと付けるstrncpy()のようなもの)
authormogami <mogami@0568b783-4c39-0410-ac80-bf13821ea2a2>
Sun, 21 Jul 2002 07:18:34 +0000 (07:18 +0000)
committermogami <mogami@0568b783-4c39-0410-ac80-bf13821ea2a2>
Sun, 21 Jul 2002 07:18:34 +0000 (07:18 +0000)
して、これにmb_strlcpy()を統合した。Angband 3.0.0にならって関数に配列のサイズ
(1024とか80とか)を渡すときはsizeof()を使うようにした。

28 files changed:
src/autopick.c
src/chuukei.c
src/cmd4.c
src/cmd6.c
src/dungeon.c
src/externs.h
src/files.c
src/inet.c
src/init1.c
src/init2.c
src/japanese.c
src/load.c
src/main-dos.c
src/main-gcu.c
src/main-ibm.c
src/main-mac-carbon.c
src/main-mac.c
src/main-win.c
src/main-x11.c
src/main.c
src/monster1.c
src/scores.c
src/script.c
src/util.c
src/wizard1.c
src/xtra1.c
src/z-util.c
src/z-util.h

index 1de4147..be61fd0 100644 (file)
@@ -1715,11 +1715,11 @@ static cptr *read_text_lines(cptr filename, bool user)
        {
                /* Hack -- drop permissions */
                safe_setuid_drop();
-               path_build(buf, 1024, ANGBAND_DIR_USER, filename);
+               path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
        }
        else
        {
-               path_build(buf, 1024, ANGBAND_DIR_PREF, filename);
+               path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename);
        }
        
        /* Open the file */
@@ -1731,7 +1731,7 @@ static cptr *read_text_lines(cptr filename, bool user)
                C_MAKE(lines_list, MAX_LINES, cptr);
 
                /* Parse it */
-               while (0 == my_fgets(fff, buf, 1024))
+               while (0 == my_fgets(fff, buf, sizeof(buf)))
                {
                        lines_list[lines++] = string_make(buf);
                        if (lines >= MAX_LINES - 1) break;
@@ -1809,7 +1809,7 @@ static bool write_text_lines(cptr filename, cptr *lines_list)
        safe_setuid_drop();
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_USER, filename);
+       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
        
        /* Open the file */
        fff = my_fopen(buf, "w");
@@ -2530,8 +2530,7 @@ void do_cmd_edit_autopick(void)
                 autopick_entry_from_object(entry, &autopick_last_destroyed_object);
                 last_destroyed = autopick_line_from_entry_kill(entry);
 
-               strncpy(last_destroyed_command, format("^L \"%s\"", last_destroyed), WID_DESC+2);
-               last_destroyed_command[WID_DESC+2] = '\0';
+               my_strcpy(last_destroyed_command, format("^L \"%s\"", last_destroyed), sizeof(last_destroyed_command));
        }
        else
        {
index 7ec440d..3fe52d7 100644 (file)
@@ -249,7 +249,7 @@ static int read_chuukei_prf(cptr prf_name)
        char buf[1024];
        FILE *fp;
 
-       path_build(buf, 1024, ANGBAND_DIR_XTRA, prf_name);
+       path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA, prf_name);
        fp = my_fopen(buf, "r");
 
        if (!fp) return (-1);
@@ -259,7 +259,7 @@ static int read_chuukei_prf(cptr prf_name)
        server_name[0] = 0;
        browse_delay = DEFAULT_DELAY;
 
-       while (0 == my_fgets(fp, buf, 1024))
+       while (0 == my_fgets(fp, buf, sizeof(buf)))
        {
                /* ¥µ¡¼¥Ð̾ */
                if (!strncmp(buf, "server:", 7))
index 999f773..f9c2c3e 100644 (file)
@@ -62,7 +62,7 @@ static void remove_auto_dump(cptr orig_file, cptr mark)
        
        while (1)
        {
-               if (my_fgets(orig_fff, buf, 1024))
+               if (my_fgets(orig_fff, buf, sizeof(buf)))
                {
                        if (between_mark)
                        {
@@ -120,7 +120,7 @@ static void remove_auto_dump(cptr orig_file, cptr mark)
                tmp_fff = my_fopen(tmp_file, "r");
                orig_fff = my_fopen(orig_file, "w");
                
-               while (!my_fgets(tmp_fff, buf, 1024))
+               while (!my_fgets(tmp_fff, buf, sizeof(buf)))
                        fprintf(orig_fff, "%s\n", buf);
                
                my_fclose(orig_fff);
@@ -261,7 +261,7 @@ errr do_cmd_write_nikki(int type, int num, cptr note)
        safe_setuid_drop();
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_USER, file_name);
+       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, file_name);
 
        /* File type is "TEXT" */
        FILE_TYPE(FILE_TYPE_TEXT);
@@ -793,7 +793,7 @@ static void do_cmd_disp_nikki(void)
        safe_setuid_drop();
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_USER, file_name);
+       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, file_name);
 
        if (p_ptr->pclass == CLASS_WARRIOR || p_ptr->pclass == CLASS_MONK || p_ptr->pclass == CLASS_SAMURAI || p_ptr->pclass == CLASS_BERSERKER)
                strcpy(tmp,subtitle[randint0(MAX_SUBTITLE-1)]);
@@ -880,7 +880,7 @@ static void do_cmd_erase_nikki(void)
        safe_setuid_drop();
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_USER, file_name);
+       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, file_name);
 
        /* Remove the file */
        fd_kill(buf);
@@ -2501,7 +2501,7 @@ static errr macro_dump(cptr fname)
        char buf[1024];
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_USER, fname);
+       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
 
        /* File type is "TEXT" */
        FILE_TYPE(FILE_TYPE_TEXT);
@@ -2666,7 +2666,7 @@ static errr keymap_dump(cptr fname)
 
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_USER, fname);
+       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
 
        /* File type is "TEXT" */
        FILE_TYPE(FILE_TYPE_TEXT);
@@ -3482,7 +3482,7 @@ void do_cmd_visuals(void)
                        if (!askfor_aux(tmp, 70)) continue;
 
                        /* Build the filename */
-                       path_build(buf, 1024, ANGBAND_DIR_USER, tmp);
+                       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, tmp);
 
                        /* Append to the file */
                        fff = open_auto_dump(buf, mark, &line_num);
@@ -3555,7 +3555,7 @@ void do_cmd_visuals(void)
                        if (!askfor_aux(tmp, 70)) continue;
 
                        /* Build the filename */
-                       path_build(buf, 1024, ANGBAND_DIR_USER, tmp);
+                       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, tmp);
 
                        /* Append to the file */
                        fff = open_auto_dump(buf, mark, &line_num);
@@ -3628,7 +3628,7 @@ void do_cmd_visuals(void)
                        if (!askfor_aux(tmp, 70)) continue;
 
                        /* Build the filename */
-                       path_build(buf, 1024, ANGBAND_DIR_USER, tmp);
+                       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, tmp);
 
                        /* Append to the file */
                        fff = open_auto_dump(buf, mark, &line_num);
@@ -4178,7 +4178,7 @@ void do_cmd_colors(void)
                        if (!askfor_aux(tmp, 70)) continue;
 
                        /* Build the filename */
-                       path_build(buf, 1024, ANGBAND_DIR_USER, tmp);
+                       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, tmp);
 
                        /* Append to the file */
                        fff = open_auto_dump(buf, mark, &line_num);
@@ -4759,7 +4759,7 @@ void do_cmd_load_screen(void)
        safe_setuid_drop();
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_USER, "dump.txt");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, "dump.txt");
 
        /* Append to the file */
        fff = my_fopen(buf, "r");
@@ -4798,7 +4798,7 @@ void do_cmd_load_screen(void)
        }
 
        /* Get the blank line */
-       if (my_fgets(fff, buf, 1024)) okay = FALSE;
+       if (my_fgets(fff, buf, sizeof(buf))) okay = FALSE;
 
 
        /* Dump the screen */
@@ -4827,7 +4827,7 @@ void do_cmd_load_screen(void)
 
 
        /* Get the blank line */
-       if (my_fgets(fff, buf, 1024)) okay = FALSE;
+       if (my_fgets(fff, buf, sizeof(buf))) okay = FALSE;
 
 
        /* Close it */
@@ -5225,7 +5225,7 @@ void do_cmd_save_screen_html_aux(char *filename, int message)
                screen_save();
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_USER, "htmldump.prf");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, "htmldump.prf");
        tmpfff = my_fopen(buf, "r");
        if (!tmpfff) {
                for (i = 0; html_head[i]; i++)
@@ -5233,7 +5233,7 @@ void do_cmd_save_screen_html_aux(char *filename, int message)
        }
        else {
                yomikomu = 0;
-               while (!my_fgets(tmpfff, buf, 1024)) {
+               while (!my_fgets(tmpfff, buf, sizeof(buf))) {
                        if (!yomikomu) {
                                if (strncmp(buf, tags[0], strlen(tags[0])) == 0)
                                        yomikomu = 1;
@@ -5296,7 +5296,7 @@ void do_cmd_save_screen_html_aux(char *filename, int message)
        else {
                rewind(tmpfff);
                yomikomu = 0;
-               while (!my_fgets(tmpfff, buf, 1024)) {
+               while (!my_fgets(tmpfff, buf, sizeof(buf))) {
                        if (!yomikomu) {
                                if (strncmp(buf, tags[2], strlen(tags[2])) == 0)
                                        yomikomu = 1;
@@ -5346,7 +5346,7 @@ static void do_cmd_save_screen_html(void)
                return;
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_USER, tmp);
+       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, tmp);
 
        msg_print(NULL);
 
@@ -5440,7 +5440,7 @@ void do_cmd_save_screen(void)
                safe_setuid_drop();
 
                /* Build the filename */
-               path_build(buf, 1024, ANGBAND_DIR_USER, "dump.txt");
+               path_build(buf, sizeof(buf), ANGBAND_DIR_USER, "dump.txt");
 
                /* File type is "TEXT" */
                FILE_TYPE(FILE_TYPE_TEXT);
@@ -7747,18 +7747,18 @@ msg_format("%d 
        if (!randint0(10) || p_ptr->image)
                {
 #ifdef JP
-               path_build(buf, 1024, ANGBAND_DIR_FILE, "timefun_j.txt");
+               path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "timefun_j.txt");
 #else
-               path_build(buf, 1024, ANGBAND_DIR_FILE, "timefun.txt");
+               path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "timefun.txt");
 #endif
 
                }
                else
                {
 #ifdef JP
-               path_build(buf, 1024, ANGBAND_DIR_FILE, "timenorm_j.txt");
+               path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "timenorm_j.txt");
 #else
-               path_build(buf, 1024, ANGBAND_DIR_FILE, "timenorm.txt");
+               path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "timenorm.txt");
 #endif
 
                }
@@ -7770,7 +7770,7 @@ msg_format("%d 
        if (!fff) return;
 
        /* Find this time */
-       while (!my_fgets(fff, buf, 1024))
+       while (!my_fgets(fff, buf, sizeof(buf)))
        {
                /* Ignore comments */
                if (!buf[0] || (buf[0] == '#')) continue;
index ba3cba8..33d9cc2 100644 (file)
@@ -2080,7 +2080,7 @@ msg_print("
                object_desc(o_name, o_ptr, TRUE, 0);
 
                /* Build the filename */
-               path_build(buf, 1024, ANGBAND_DIR_FILE, q);
+               path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, q);
 
                /* Peruse the help file */
                (void)show_file(TRUE, buf, o_name, 0, 0);
index e6122fe..766d106 100644 (file)
@@ -6273,7 +6273,7 @@ quit("
                character_icky = TRUE;
 
                /* Build the filename */
-               path_build(buf, 1024, ANGBAND_DIR_APEX, "scores.raw");
+               path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
 
                /* Open the high score file, for reading/writing */
                highscore_fd = fd_open(buf, O_RDWR);
index 823a9b6..8a1e3d1 100644 (file)
@@ -1180,6 +1180,10 @@ extern byte gamma_table[256];
 extern void build_gamma_table(int gamma);
 #endif /* SUPPORT_GAMMA */
 
+extern size_t my_strcpy(char *buf, const char *src, size_t bufsize);
+extern size_t my_strcat(char *buf, const char *src, size_t bufsize);
+
+
 /* xtra1.c */
 extern bool is_daytime(void);
 extern void extract_day_hour_min(int *day, int *hour, int *min);
@@ -1482,7 +1486,6 @@ extern void jverb2( const char *in , char *out);
 extern void jverb3( const char *in , char *out);
 extern void jverb( const char *in , char *out , int flag);
 extern char* strstr_j(cptr str1, cptr str2);
-extern size_t mb_strlcpy(char *dst, const char *src, size_t size);
 extern void codeconv(char *str);
 extern bool iskanji2(cptr s, int x);
 #endif
index 6b69367..fbc0a57 100644 (file)
@@ -1104,7 +1104,7 @@ static errr process_pref_file_aux(cptr name, bool read_pickpref)
        if (!fp) return (-1);
 
        /* Process the file */
-       while (0 == my_fgets(fp, buf, 1024))
+       while (0 == my_fgets(fp, buf, sizeof(buf)))
        {
                /* Count lines */
                line++;
@@ -1216,7 +1216,7 @@ errr process_pref_file(cptr name)
        errr err1, err2;
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_PREF, name);
+       path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, name);
 
        /* Process the system pref file */
        err1 = process_pref_file_aux(buf, FALSE);
@@ -1229,7 +1229,7 @@ errr process_pref_file(cptr name)
        safe_setuid_drop();
        
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_USER, name);
+       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
        
        /* Process the user pref file */
        err2 = process_pref_file_aux(buf, FALSE);
@@ -1315,7 +1315,7 @@ errr check_time_init(void)
 
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_FILE, "time.txt");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "time.txt");
 
        /* Open the file */
        fp = my_fopen(buf, "r");
@@ -1327,7 +1327,7 @@ errr check_time_init(void)
        check_time_flag = TRUE;
 
        /* Parse the file */
-       while (0 == my_fgets(fp, buf, 80))
+       while (0 == my_fgets(fp, buf, sizeof(buf)))
        {
                /* Skip comments and blank lines */
                if (!buf[0] || (buf[0] == '#')) continue;
@@ -1439,7 +1439,7 @@ errr check_load_init(void)
 
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_FILE, "load.txt");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "load.txt");
 
        /* Open the "load" file */
        fp = my_fopen(buf, "r");
@@ -1454,7 +1454,7 @@ errr check_load_init(void)
        (void)gethostname(thishost, (sizeof thishost) - 1);
 
        /* Parse it */
-       while (0 == my_fgets(fp, buf, 1024))
+       while (0 == my_fgets(fp, buf, sizeof(buf)))
        {
                int value;
 
@@ -4885,7 +4885,7 @@ errr file_character(cptr name, bool full)
        safe_setuid_drop();
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_USER, name);
+       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
 
        /* File type is "TEXT" */
        FILE_TYPE(FILE_TYPE_TEXT);
@@ -5147,7 +5147,7 @@ sprintf(caption, "
 
 
                /* Build the filename */
-               path_build(path, 1024, ANGBAND_DIR_HELP, name);
+               path_build(path, sizeof(path), ANGBAND_DIR_HELP, name);
 
                /* Open the file */
                fff = my_fopen(path, "r");
@@ -5165,7 +5165,7 @@ sprintf(caption, "
 
 
                /* Build the filename */
-               path_build(path, 1024, ANGBAND_DIR_INFO, name);
+               path_build(path, sizeof(path), ANGBAND_DIR_INFO, name);
 
                /* Open the file */
                fff = my_fopen(path, "r");
@@ -5175,7 +5175,7 @@ sprintf(caption, "
        if (!fff)
        {
                /* Build the filename */
-               path_build(path, 1024, ANGBAND_DIR, name);
+               path_build(path, sizeof(path), ANGBAND_DIR, name);
 
                for (i = 0; path[i]; i++)
                        if ('\\' == path[i])
@@ -5215,7 +5215,7 @@ msg_format("'%s'
                char *str;
 
                /* Read a line or stop */
-               if (my_fgets(fff, buf, 1024)) break;
+               if (my_fgets(fff, buf, sizeof(buf))) break;
 
                /* Get a color */
                if (prefix(buf, "#####")) str = &buf[6];
@@ -5296,7 +5296,7 @@ msg_format("'%s'
                while (next < line)
                {
                        /* Get a line */
-                       if (my_fgets(fff, buf, 1024)) break;
+                       if (my_fgets(fff, buf, sizeof(buf))) break;
 
                        /* Skip tags/links */
                        if (prefix(buf, "***** ")) continue;
@@ -5315,7 +5315,7 @@ msg_format("'%s'
                        if (!i) line = next;
 
                        /* Get a line of the file or stop */
-                       if (my_fgets(fff, buf, 1024)) break;
+                       if (my_fgets(fff, buf, sizeof(buf))) break;
 
                        /* Hack -- skip "special" lines */
                        if (prefix(buf, "***** ")) continue;
@@ -5638,7 +5638,7 @@ strcpy(tmp, "jhelp.hlp");
                        safe_setuid_drop();
 
                        /* Build the filename */
-                       path_build(buff, 1024, ANGBAND_DIR_USER, xtmp);
+                       path_build(buff, sizeof(buff), ANGBAND_DIR_USER, xtmp);
 
                        /* Hack -- Re-Open the file */
                        fff = my_fopen(path, "r");
@@ -5662,7 +5662,7 @@ msg_print("
                        my_fputs(ffp, xtmp, 80);
                        my_fputs(ffp, "\n", 80);
 
-                       while (!my_fgets(fff, buff, 80))
+                       while (!my_fgets(fff, buff, sizeof(buff)))
                                my_fputs(ffp, buff, 80);
 
                        /* Close it */
@@ -5881,7 +5881,7 @@ quit_fmt("'%s' 
 #endif /* VM */
 
                /* Build the filename */
-               path_build(savefile, 1024, ANGBAND_DIR_SAVE, temp);
+               path_build(savefile, sizeof(savefile), ANGBAND_DIR_SAVE, temp);
        }
 }
 
@@ -6236,7 +6236,7 @@ static void make_bones(void)
                        sprintf(tmp, "bone.%03d", dun_level);
 
                        /* Build the filename */
-                       path_build(str, 1024, ANGBAND_DIR_BONE, tmp);
+                       path_build(str, sizeof(str), ANGBAND_DIR_BONE, tmp);
 
                        /* Attempt to open the bones file */
                        fp = my_fopen(str, "r");
@@ -6312,9 +6312,9 @@ static void print_tomb(void)
 
                /* Build the filename */
 #ifdef JP
-               path_build(buf, 1024, ANGBAND_DIR_FILE, "dead_j.txt");
+               path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "dead_j.txt");
 #else
-               path_build(buf, 1024, ANGBAND_DIR_FILE, "dead.txt");
+               path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "dead.txt");
 #endif
 
 
@@ -6327,7 +6327,7 @@ static void print_tomb(void)
                        int i = 0;
 
                        /* Dump the file to the screen */
-                       while (0 == my_fgets(fp, buf, 1024))
+                       while (0 == my_fgets(fp, buf, sizeof(buf)))
                        {
                                /* Display and advance */
                                put_str(buf, i++, 0);
@@ -6810,7 +6810,7 @@ void close_game(void)
 
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_APEX, "scores.raw");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
 
        /* Open the high score file, for reading/writing */
        highscore_fd = fd_open(buf, O_RDWR);
@@ -6989,7 +6989,7 @@ errr get_rnd_line(cptr file_name, int entry, char *output)
 
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_FILE, file_name);
+       path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, file_name);
 
        /* Open the file */
        fp = my_fopen(buf, "r");
@@ -7001,7 +7001,7 @@ errr get_rnd_line(cptr file_name, int entry, char *output)
        while (TRUE)
        {
                /* Get a line from the file */
-               if (my_fgets(fp, buf, 1024) == 0)
+               if (my_fgets(fp, buf, sizeof(buf)) == 0)
                {
                        /* Count the lines */
                        line_num++;
@@ -7065,7 +7065,7 @@ errr get_rnd_line(cptr file_name, int entry, char *output)
        while (TRUE)
        {
                /* Get the line */
-               if (my_fgets(fp, buf, 1024) == 0)
+               if (my_fgets(fp, buf, sizeof(buf)) == 0)
                {
                        /* Count the lines */
                        line_num++;
@@ -7105,7 +7105,7 @@ errr get_rnd_line(cptr file_name, int entry, char *output)
 
                        while(TRUE)
                        {
-                               test = my_fgets(fp, buf, 1024);
+                               test = my_fgets(fp, buf, sizeof(buf));
                                if(test || buf[0] != '#')
                                        break;
                        }
@@ -7171,7 +7171,7 @@ errr process_pickpref_file(cptr name)
        safe_setuid_drop();
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_USER, name);
+       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
 
        err = process_pref_file_aux(buf, TRUE);
 
@@ -7229,9 +7229,9 @@ u32b counts_read(int where)
        char buf[1024];
 
 #ifdef JP
-       path_build(buf, 1024, ANGBAND_DIR_DATA, "z_info_j.raw");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, "z_info_j.raw");
 #else
-       path_build(buf, 1024, ANGBAND_DIR_DATA, "z_info.raw");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, "z_info.raw");
 #endif
        fd = fd_open(buf, O_RDONLY);
 
@@ -7250,9 +7250,9 @@ errr counts_write(int where, u32b count)
        char buf[1024];
 
 #ifdef JP
-       path_build(buf, 1024, ANGBAND_DIR_DATA, "z_info_j.raw");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, "z_info_j.raw");
 #else
-       path_build(buf, 1024, ANGBAND_DIR_DATA, "z_info.raw");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, "z_info.raw");
 #endif
        fd = fd_open(buf, O_RDWR);
        if (fd < 0)
index 585d730..eb75548 100644 (file)
@@ -112,7 +112,7 @@ static void set_proxy(void)
        char tmp[8];
 #endif
 
-       path_build(buf, 1024, ANGBAND_DIR_PREF, "proxy.prf");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, "proxy.prf");
 
        /* ¥Õ¥¡¥¤¥ë¤«¤éÀßÄê¤òÆɤࡣ */
        fp = my_fopen(buf, "r");
@@ -125,7 +125,7 @@ static void set_proxy(void)
                return;
        }
 
-       while (my_fgets(fp, buf, 1024)==0)
+       while (my_fgets(fp, buf, sizeof(buf))==0)
        {
                if (buf[0] != '#' && buf[0] != '\0') break;
        }
index 2be2ce0..629ad36 100644 (file)
@@ -808,7 +808,7 @@ errr init_info_txt(FILE *fp, char *buf, header *head,
        head->text_size = 0;
 
        /* Parse */
-       while (0 == my_fgets(fp, buf, 1024))
+       while (0 == my_fgets(fp, buf, sizeof(buf)))
        {
                /* Advance the line number */
                error_line++;
@@ -3961,7 +3961,7 @@ errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax)
 
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_EDIT, name);
+       path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
 
        /* Open the file */
        fp = my_fopen(buf, "r");
@@ -3971,7 +3971,7 @@ errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax)
 
 
        /* Process the file */
-       while (0 == my_fgets(fp, buf, 1024))
+       while (0 == my_fgets(fp, buf, sizeof(buf)))
        {
                /* Count lines */
                num++;
index a1b9e32..fef4978 100644 (file)
@@ -173,7 +173,7 @@ void init_file_paths(char *path)
 #ifdef PRIVATE_USER_PATH
 
        /* Build the path to the user specific directory */
-       path_build(buf, 1024, PRIVATE_USER_PATH, VERSION_NAME);
+       path_build(buf, sizeof(buf), PRIVATE_USER_PATH, VERSION_NAME);
 
        /* Build a relative path name */
        ANGBAND_DIR_USER = string_make(buf);
@@ -300,7 +300,7 @@ static errr check_modification_date(int fd, cptr template_file)
        struct stat txt_stat, raw_stat;
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_EDIT, template_file);
+       path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, template_file);
 
        /* Access stats on text file */
        if (stat(buf, &txt_stat))
@@ -439,9 +439,9 @@ static errr init_info(cptr filename, header *head,
 
        /* Build the filename */
 #ifdef JP
-       path_build(buf, 1024, ANGBAND_DIR_DATA, format("%s_j.raw", filename));
+       path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s_j.raw", filename));
 #else
-       path_build(buf, 1024, ANGBAND_DIR_DATA, format("%s.raw", filename));
+       path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s.raw", filename));
 #endif
 
 
@@ -486,7 +486,7 @@ static errr init_info(cptr filename, header *head,
 
                /* Build the filename */
 
-               path_build(buf, 1024, ANGBAND_DIR_EDIT, format("%s_j.txt", filename));
+               path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, format("%s_j.txt", filename));
 
                /* Open the file */
                fp = my_fopen(buf, "r");
@@ -546,9 +546,9 @@ static errr init_info(cptr filename, header *head,
 
                /* Build the filename */
 #ifdef JP
-               path_build(buf, 1024, ANGBAND_DIR_DATA, format("%s_j.raw", filename));
+               path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s_j.raw", filename));
 #else
-               path_build(buf, 1024, ANGBAND_DIR_DATA, format("%s.raw", filename));
+               path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s.raw", filename));
 #endif
 
 
@@ -594,9 +594,9 @@ static errr init_info(cptr filename, header *head,
 
                /* Build the filename */
 #ifdef JP
-               path_build(buf, 1024, ANGBAND_DIR_DATA, format("%s_j.raw", filename));
+               path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s_j.raw", filename));
 #else
-               path_build(buf, 1024, ANGBAND_DIR_DATA, format("%s.raw", filename));
+               path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s.raw", filename));
 #endif
 
 
@@ -1986,9 +1986,9 @@ void init_angband(void)
 
        /* Build the filename */
 #ifdef JP
-       path_build(buf, 1024, ANGBAND_DIR_FILE, "news_j.txt");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "news_j.txt");
 #else
-       path_build(buf, 1024, ANGBAND_DIR_FILE, "news.txt");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "news.txt");
 #endif
 
 
@@ -2023,9 +2023,9 @@ void init_angband(void)
 
        /* Build the filename */
 #ifdef JP
-       path_build(buf, 1024, ANGBAND_DIR_FILE, "news_j.txt");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "news_j.txt");
 #else
-       path_build(buf, 1024, ANGBAND_DIR_FILE, "news.txt");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "news.txt");
 #endif
 
 
@@ -2038,7 +2038,7 @@ void init_angband(void)
                int i = 0;
 
                /* Dump the file to the screen */
-               while (0 == my_fgets(fp, buf, 1024))
+               while (0 == my_fgets(fp, buf, sizeof(buf)))
                {
                        /* Display and advance */
                        Term_putstr(0, i++, -1, TERM_WHITE, buf);
@@ -2055,7 +2055,7 @@ void init_angband(void)
        /*** Verify (or create) the "high score" file ***/
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_APEX, "scores.raw");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
 
        /* Attempt to open the high score file */
        fd = fd_open(buf, O_RDONLY);
index 7e923e2..0c2b1bf 100644 (file)
@@ -141,32 +141,6 @@ char* strstr_j(const char* s, const char* t)
        return NULL;
 }
 
-/* 2¥Ð¥¤¥Èʸ»ú¤ò¹Íθ¤·¤Ê¤¬¤éºÇÂç n ¥Ð¥¤¥Èʸ»úÎó¤ò¥³¥Ô¡¼¤¹¤ë */
-size_t mb_strlcpy(char *dst, const char *src, size_t size)
-{
-       unsigned char *d = (unsigned char*)dst;
-       const unsigned char *s = (unsigned char*)src;
-       size_t n = 0;
-
-       /* reserve for NUL termination */
-       size--;
-
-       /* Copy as many bytes as will fit */
-       while(n < size) {
-               if (iskanji(*s)) {
-                       if(n + 2 >= size || !*(s+1)) break;
-                       *d++ = *s++;
-                       *d++ = *s++;
-                       n += 2;
-               } else {
-                       *d++ = *s++;
-                       n++;
-               }
-       }
-       *d = '\0';
-       while(*s++) n++;
-       return n;
-}
 
 /*
  * str¤ò´Ä¶­¤Ë¹ç¤Ã¤¿Ê¸»ú¥³¡¼¥É¤ËÊÑ´¹¤¹¤ë¡£
index b6cef91..4cfc7b9 100644 (file)
@@ -433,12 +433,12 @@ static void rd_item(object_type *o_ptr)
         rd_byte(&o_ptr->feeling);
 
        /* Inscription */
-       rd_string(buf, 128);
+       rd_string(buf, sizeof(buf));
 
        /* Save the inscription */
        if (buf[0]) o_ptr->inscription = quark_add(buf);
 
-       rd_string(buf, 128);
+       rd_string(buf, sizeof(buf));
        if (buf[0]) o_ptr->art_name = quark_add(buf);
 
        /* The Python object */
@@ -611,7 +611,7 @@ static void rd_monster(monster_type *m_ptr)
        }
        else
        {
-               rd_string(buf, 128);
+               rd_string(buf, sizeof(buf));
                if (buf[0]) m_ptr->nickname = quark_add(buf);
        }
 
@@ -1079,7 +1079,7 @@ static void rd_ghost(void)
        char buf[64];
 
        /* Strip name */
-       rd_string(buf, 64);
+       rd_string(buf, sizeof(buf));
 
        /* Strip old data */
        strip_bytes(60);
@@ -1122,7 +1122,7 @@ static void load_quick_start(void)
 
        for (i = 0; i < 8; i++) rd_s16b(&previous_char.vir_types[i]);
 
-       for (i = 0; i < 4; i++) rd_string(previous_char.history[i], 60);
+       for (i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
 
        rd_byte(&previous_char.quests);
 
@@ -1140,15 +1140,15 @@ static void rd_extra(void)
        byte tmp8u;
        s16b tmp16s;
 
-       rd_string(player_name, 32);
+       rd_string(player_name, sizeof(player_name));
 
-       rd_string(p_ptr->died_from, 80);
+       rd_string(p_ptr->died_from, sizeof(p_ptr->died_from));
 
        load_quick_start();
 
        for (i = 0; i < 4; i++)
        {
-               rd_string(p_ptr->history[i], 60);
+               rd_string(p_ptr->history[i], sizeof(p_ptr->history[i]));
        }
 
        /* Class/Race/Seikaku/Gender/Spells */
@@ -1832,7 +1832,7 @@ static void rd_messages(void)
        for (i = 0; i < num; i++)
        {
                /* Read the message */
-               rd_string(buf, 128);
+               rd_string(buf, sizeof(buf));
 
                /* Save the message */
                message_add(buf);
@@ -2828,7 +2828,7 @@ note("
        if (!z_older_than(11, 0, 9))
        {
                char buf[SCREEN_BUF_SIZE];
-               rd_string(buf, SCREEN_BUF_SIZE);
+               rd_string(buf, sizeof(buf));
                if (buf[0]) screen_dump = string_make(buf);
        }
 
index cba0328..158ccbf 100644 (file)
@@ -1411,7 +1411,7 @@ static void dos_dump_screen(void)
        get_palette(pal);
 
        /* Build the filename for the screen-dump */
-       path_build(filename, 1024, ANGBAND_DIR_USER, "dump.bmp");
+       path_build(filename, sizeof(filename), ANGBAND_DIR_USER, "dump.bmp");
 
        /* Save it */
        save_bmp(filename, bmp, pal);
@@ -1675,7 +1675,7 @@ static bool init_windows(void)
                strcpy(buf, get_config_string(section, "font_file", "xm8x13.fnt"));
 
                /* Build the name of the font file */
-               path_build(filename, 1024, xtra_font_dir, buf);
+               path_build(filename, sizeof(filename), xtra_font_dir, buf);
 
                /* Load a "*.fnt" file */
                if (suffix(filename, ".fnt"))
@@ -1743,7 +1743,7 @@ static void init_background(void)
                strcpy(buf, get_config_string("Background", format("Background-%d", i), ""));
 
                /* Build the filename for the background-bitmap */
-               path_build(filename, 1024, xtra_graf_dir, buf);
+               path_build(filename, sizeof(filename), xtra_graf_dir, buf);
 
                /* Try to open the bitmap file */
                background[i] = load_bitmap(filename, background_pallete);
@@ -1800,7 +1800,7 @@ static bool init_graphics(void)
                num_windows = get_config_int(section, "num_windows", 1);
 
                /* Build the name of the bitmap file */
-               path_build(filename, 1024, xtra_graf_dir, name_tiles);
+               path_build(filename, sizeof(filename), xtra_graf_dir, name_tiles);
 
                /* Open the bitmap file */
                if ((tiles = load_bitmap(filename, tiles_pallete)) != NULL)
@@ -1913,7 +1913,7 @@ static bool init_sound(void)
 #endif /* USE_MOD_FILES */
 
                /* Access the new sample */
-               path_build(filename, 1024, xtra_sound_dir, "sound.cfg");
+               path_build(filename, sizeof(filename), xtra_sound_dir, "sound.cfg");
 
                /* Read config info from "lib/xtra/sound/sound.cfg" */
                override_config_file(filename);
@@ -1933,7 +1933,7 @@ static bool init_sound(void)
                        for (j = 0; j < sample_count[i]; j++)
                        {
                                /* Access the new sample */
-                               path_build(filename, 1024, xtra_sound_dir, argv[j]);
+                               path_build(filename, sizeof(filename), xtra_sound_dir, argv[j]);
 
                                /* Load the sample */
                                samples[i][j] = load_sample(filename);
@@ -2033,7 +2033,7 @@ static void play_song(void)
 #endif /* USE_MOD_FILES */
 
        /* Access the new song */
-       path_build(filename, 1024, xtra_music_dir, music_files[current_song - 1]);
+       path_build(filename, sizeof(filename), xtra_music_dir, music_files[current_song - 1]);
 
        /* Load and play the new song */
        midi_song = load_midi(filename);
@@ -2133,16 +2133,16 @@ errr init_dos(void)
        quit_aux = dos_quit_hook;
 
        /* Build the "graf" path */
-       path_build(xtra_graf_dir, 1024, ANGBAND_DIR_XTRA, "graf");
+       path_build(xtra_graf_dir, sizeof(xtra_graf_dir), ANGBAND_DIR_XTRA, "graf");
 
        /* Build the "font" path */
-       path_build(xtra_font_dir, 1024, ANGBAND_DIR_XTRA, "font");
+       path_build(xtra_font_dir, sizeof(xtra_font_dir), ANGBAND_DIR_XTRA, "font");
 
        /* Build the "sound" path */
-       path_build(xtra_sound_dir, 1024, ANGBAND_DIR_XTRA, "sound");
+       path_build(xtra_sound_dir, sizeof(xtra_sound_dir), ANGBAND_DIR_XTRA, "sound");
 
        /* Build the "music" path */
-       path_build(xtra_music_dir, 1024, ANGBAND_DIR_XTRA, "music");
+       path_build(xtra_music_dir, sizeof(xtra_music_dir), ANGBAND_DIR_XTRA, "music");
 
        /* Initialize the windows */
        init_windows();
index feb8af1..565ee7c 100644 (file)
@@ -668,7 +668,7 @@ static bool init_sound(void)
          sprintf(wav, "%s.wav", angband_sound_name[i]);
 
          /* Access the sound */
-         path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, wav);
+         path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_SOUND, wav);
 
          /* Save the sound filename, if it exists */
          if (check_file(buf)) sound_file[i] = string_make(buf);
@@ -1200,7 +1200,7 @@ errr init_gcu(int argc, char *argv[])
 #ifdef USE_SOUND
 
    /* Build the "sound" path */
-   path_build(path, 1024, ANGBAND_DIR_XTRA, "sound");
+   path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
 
    /* Allocate the path */
    ANGBAND_DIR_XTRA_SOUND = string_make(path);
index 2b3aaaa..daf0595 100644 (file)
@@ -1303,7 +1303,7 @@ errr init_ibm(void)
                char buf[4096];
 
                /* Build the filename */
-               path_build(buf, 1024, ANGBAND_DIR_XTRA, "angband.fnt");
+               path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA, "angband.fnt");
 
                /* Open the file */
                f = fopen(buf, "rb");
index 013f863..6fcdda5 100644 (file)
@@ -2303,7 +2303,7 @@ static int getshort(void)
 {
        int x = 0;
        char buf[256];
-       if (0 == my_fgets(fff, buf, 256)) x = atoi(buf);
+       if (0 == my_fgets(fff, buf, sizeof(buf))) x = atoi(buf);
        return (x);
 }
 
@@ -2747,7 +2747,7 @@ static void init_chuukei( void )
        char tmp[1024];
        FILE *fp;
        
-       path_build(path, 1024, ANGBAND_DIR_XTRA, "chuukei.txt");
+       path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "chuukei.txt");
 
        fp = fopen(path, "r");
        if(!fp)
@@ -5029,9 +5029,9 @@ static void init_stuff(void)
 
                /* Build the filename */
                #ifdef JP
-                       path_build(path, 1024, ANGBAND_DIR_FILE, "news_j.txt");
+                       path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news_j.txt");
                #else
-                       path_build(path, 1024, ANGBAND_DIR_FILE, "news.txt");
+                       path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news.txt");
                #endif
 
                /* Attempt to open and close that file */
index 5d52a12..28def8c 100644 (file)
@@ -2271,7 +2271,7 @@ static int getshort(void)
 {
        int x = 0;
        char buf[256];
-       if (0 == my_fgets(fff, buf, 256)) x = atoi(buf);
+       if (0 == my_fgets(fff, buf, sizeof(buf))) x = atoi(buf);
        return (x);
 }
 
@@ -2797,7 +2797,7 @@ static void init_chuukei( void )
        char tmp[1024];
        FILE *fp;
        
-       path_build(path, 1024, ANGBAND_DIR_XTRA, "chuukei.txt");
+       path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "chuukei.txt");
 
        fp = fopen(path, "r");
        if(!fp)
@@ -5098,9 +5098,9 @@ static void init_stuff(void)
 
                /* Build the filename */
                #ifdef JP
-                       path_build(path, 1024, ANGBAND_DIR_FILE, "news_j.txt");
+                       path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news_j.txt");
                #else
-                       path_build(path, 1024, ANGBAND_DIR_FILE, "news.txt");
+                       path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news.txt");
                #endif
 
                /* Attempt to open and close that file */
index 0408ca4..25d831c 100644 (file)
@@ -1419,7 +1419,7 @@ static bool init_graphics(void)
                }
 
                /* Access the bitmap file */
-               path_build(buf, 1024, ANGBAND_DIR_XTRA_GRAF, name);
+               path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
 
                /* Load the bitmap or quit */
                if (!ReadDIB(data[0].w, buf, &infGraph))
@@ -1442,7 +1442,7 @@ static bool init_graphics(void)
                if (arg_graphics == GRAPHICS_ADAM_BOLT)
                {
                        /* Access the mask file */
-                       path_build(buf, 1024, ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
+                       path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
 
                        /* Load the bitmap or quit */
                        if (!ReadDIB(data[0].w, buf, &infMask))
@@ -1500,7 +1500,7 @@ static bool init_sound(void)
                        sprintf(wav, "%s.wav", angband_sound_name[i]);
 
                        /* Access the sound */
-                       path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, wav);
+                       path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_SOUND, wav);
 
                        /* Save the sound filename, if it exists */
                        if (check_file(buf)) sound_file[i] = string_make(buf);
@@ -1716,7 +1716,7 @@ static void term_change_font(term_data *td)
                if (term_force_font(td, tmp))
                {
                        /* Access the standard font file */
-                       path_build(tmp, 1024, ANGBAND_DIR_XTRA_FONT, "8X13.FON");
+                       path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
 
                        /* Force the use of that font */
                        (void)term_force_font(td, tmp);
@@ -2845,13 +2845,13 @@ static void init_windows(void)
                td->tile_hgt = td->font_hgt;
 #else
                /* Access the standard font file */
-               path_build(buf, 1024, ANGBAND_DIR_XTRA_FONT, td->font_want);
+               path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
 
                /* Activate the chosen font */
                if (term_force_font(td, buf))
                {
                        /* Access the standard font file */
-                       path_build(buf, 1024, ANGBAND_DIR_XTRA_FONT, "8X13.FON");
+                       path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
 
                        /* Force the use of that font */
                        (void)term_force_font(td, buf);
@@ -3373,7 +3373,7 @@ static void process_menus(WORD wCmd)
                        char buf[1024];
 
                        /* Build the filename */
-                       path_build(buf, 1024, ANGBAND_DIR_APEX, "scores.raw");
+                       path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
 
                        /* Open the binary high score file, for reading */
                        highscore_fd = fd_open(buf, O_RDONLY);
@@ -3859,7 +3859,7 @@ static void process_menus(WORD wCmd)
                {
 #ifdef HTML_HELP
                        char tmp[1024];
-                       path_build(tmp, 1024, ANGBAND_DIR_XTRA_HELP, "zangband.chm");
+                       path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
                        if (check_file(tmp))
                        {
                                HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
@@ -3879,7 +3879,7 @@ static void process_menus(WORD wCmd)
 #else /* HTML_HELP */
                        char buf[1024];
                        char tmp[1024];
-                       path_build(tmp, 1024, ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
+                       path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
                        if (check_file(tmp))
                        {
                                sprintf(buf, "winhelp.exe %s", tmp);
@@ -4722,9 +4722,9 @@ static void init_stuff(void)
 
        /* Build the filename */
 #ifdef JP
-       path_build(path, 1024, ANGBAND_DIR_FILE, "news_j.txt");
+       path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news_j.txt");
 #else
-       path_build(path, 1024, ANGBAND_DIR_FILE, "news.txt");
+       path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news.txt");
 #endif
 
 
@@ -4734,7 +4734,7 @@ static void init_stuff(void)
 
 #ifndef JP
        /* Build the "font" path */
-       path_build(path, 1024, ANGBAND_DIR_XTRA, "font");
+       path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
 
        /* Allocate the path */
        ANGBAND_DIR_XTRA_FONT = string_make(path);
@@ -4743,7 +4743,7 @@ static void init_stuff(void)
        validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
 
        /* Build the filename */
-       path_build(path, 1024, ANGBAND_DIR_XTRA_FONT, "8X13.FON");
+       path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
 
        /* Hack -- Validate the basic font */
        validate_file(path);
@@ -4753,7 +4753,7 @@ static void init_stuff(void)
 #ifdef USE_GRAPHICS
 
        /* Build the "graf" path */
-       path_build(path, 1024, ANGBAND_DIR_XTRA, "graf");
+       path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
 
        /* Allocate the path */
        ANGBAND_DIR_XTRA_GRAF = string_make(path);
@@ -4767,7 +4767,7 @@ static void init_stuff(void)
 #ifdef USE_SOUND
 
        /* Build the "sound" path */
-       path_build(path, 1024, ANGBAND_DIR_XTRA, "sound");
+       path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
 
        /* Allocate the path */
        ANGBAND_DIR_XTRA_SOUND = string_make(path);
@@ -4780,7 +4780,7 @@ static void init_stuff(void)
 #ifdef USE_MUSIC
 
        /* Build the "music" path */
-       path_build(path, 1024, ANGBAND_DIR_XTRA, "music");
+       path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
 
        /* Allocate the path */
        ANGBAND_DIR_XTRA_MUSIC = string_make(path);
@@ -4791,7 +4791,7 @@ static void init_stuff(void)
 #endif /* USE_MUSIC */
 
        /* Build the "help" path */
-       path_build(path, 1024, ANGBAND_DIR_XTRA, "help");
+       path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
 
        /* Allocate the path */
        ANGBAND_DIR_XTRA_HELP = string_make(path);
index f0a2438..ce5371d 100644 (file)
@@ -2265,7 +2265,7 @@ static void init_sound(void)
        char dir_xtra_sound[1024];
                
        /* Build the "sound" path */
-       path_build(dir_xtra_sound, 1024, ANGBAND_DIR_XTRA, "sound");
+       path_build(dir_xtra_sound, sizeof(dir_xtra_sound), ANGBAND_DIR_XTRA, "sound");
                
        /* Prepare the sounds */
        for (i = 1; i < SOUND_MAX; i++)
@@ -2274,7 +2274,7 @@ static void init_sound(void)
                sprintf(wav, "%s.wav", angband_sound_name[i]);
                
                /* Access the sound */
-               path_build(buf, 1024, dir_xtra_sound, wav);
+               path_build(buf, sizeof(buf), dir_xtra_sound, wav);
                
                /* Save the sound filename, if it exists */
                if (check_file(buf)) sound_file[i] = string_make(buf);
@@ -3209,7 +3209,7 @@ errr init_x11(int argc, char *argv[])
        {
        case GRAPHICS_ORIGINAL:
                /* Try the "8x8.bmp" file */
-               path_build(filename, 1024, ANGBAND_DIR_XTRA, "graf/8x8.bmp");
+               path_build(filename, sizeof(filename), ANGBAND_DIR_XTRA, "graf/8x8.bmp");
 
                /* Use the "8x8.bmp" file if it exists */
                if (0 == fd_close(fd_open(filename, O_RDONLY)))
@@ -3226,7 +3226,7 @@ errr init_x11(int argc, char *argv[])
 
        case GRAPHICS_ADAM_BOLT:
                /* Try the "16x16.bmp" file */
-               path_build(filename, 1024, ANGBAND_DIR_XTRA, "graf/16x16.bmp");
+               path_build(filename, sizeof(filename), ANGBAND_DIR_XTRA, "graf/16x16.bmp");
 
                /* Use the "16x16.bmp" file if it exists */
                if (0 == fd_close(fd_open(filename, O_RDONLY)))
index 6fc30ac..c9bf698 100644 (file)
@@ -83,7 +83,7 @@ static void create_user_dir(void)
        mkdir(dirpath, 0700);
 
        /* Build the path to the variant-specific sub-directory */
-       path_build(subdirpath, 1024, dirpath, VERSION_NAME);
+       path_build(subdirpath, sizeof(subdirpath), dirpath, VERSION_NAME);
 
        /* Create the directory */
        mkdir(subdirpath, 0700);
index 04ad489..71204ef 100644 (file)
@@ -418,9 +418,9 @@ static void roff_aux(int r_idx, int mode)
 
                /* Build the filename */
 #ifdef JP
-path_build(buf, 1024, ANGBAND_DIR_DATA, "r_info_j.raw");
+path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, "r_info_j.raw");
 #else
-               path_build(buf, 1024, ANGBAND_DIR_DATA, "r_info.raw");
+               path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, "r_info.raw");
 #endif
 
 
index d7d8b46..c361aa5 100644 (file)
@@ -388,7 +388,7 @@ void display_scores(int from, int to)
        char buf[1024];
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_APEX, "scores.raw");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
 
        /* Open the binary high score file, for reading */
        highscore_fd = fd_open(buf, O_RDONLY);
@@ -526,40 +526,20 @@ errr top_twenty(void)
        sprintf(the_score.max_dun, "%3d", max_dlv[dungeon_type]);
 
        /* Save the cause of death (31 chars) */
-#ifdef JP
-#if 0
+       if (strlen(p_ptr->died_from) >= sizeof(the_score.how))
        {
-               /* 2byte Ê¸»ú¤ò¹Íθ¤·¤Ê¤¬¤é¥³¥Ô¡¼(EUC ¤ò²¾Äê) */
-               int cnt = 0;
-               unsigned char *d = (unsigned char*)p_ptr->died_from;
-               unsigned char *h = (unsigned char*)the_score.how;
-               while(*d && cnt < 31){
-                       if(iskanji(*d)){
-                               if(cnt + 2 > 31) break;
-                               *h++ = *d++;
-                               *h++ = *d++;
-                               cnt += 2;
-                       }else{
-                               if(cnt + 1 > 31) break;
-                               *h++ = *d++;
-                               cnt++;
-                       }
-               }
-               *h = '\0';
-       }
-#endif
-       if (strlen(p_ptr->died_from) >= 39)
-       {
-               mb_strlcpy(the_score.how, p_ptr->died_from, 37+1);
+#ifdef JP
+               my_strcpy(the_score.how, p_ptr->died_from, sizeof(the_score.how) - 2);
                strcat(the_score.how, "¡Ä");
+#else
+               my_strcpy(the_score.how, p_ptr->died_from, sizeof(the_score.how) - 3);
+               strcat(the_score.how, "...");
+#endif
        }
        else
+        {
                strcpy(the_score.how, p_ptr->died_from);
-
-#else
-       sprintf(the_score.how, "%-.31s", p_ptr->died_from);
-#endif
-
+        }
 
        /* Lock (for writing) the highscore file, or fail */
        if (fd_lock(highscore_fd, F_WRLCK)) return (1);
@@ -700,7 +680,7 @@ void show_highclass(int building)
        screen_save();
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_APEX, "scores.raw");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
 
        highscore_fd = fd_open(buf, O_RDONLY);
 
@@ -795,7 +775,7 @@ sprintf(tmp_str,"
        prt(tmp_str, 5, 15);
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_APEX, "scores.raw");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
 
        highscore_fd = fd_open(buf, O_RDONLY);
 
index ad391d3..a498f98 100644 (file)
@@ -34,12 +34,12 @@ errr script_execute(char *name)
                if (name[0] != '\0')
                {
                        /* Build the filename */
-                       path_build(buf, 1024, ANGBAND_DIR_SCRIPT, name);
+                       path_build(buf, sizeof(buf), ANGBAND_DIR_SCRIPT, name);
                }
                else
                {
                        /* Build the filename */
-                       path_build(buf, 1024, ANGBAND_DIR_SCRIPT, "idle.py");
+                       path_build(buf, sizeof(buf), ANGBAND_DIR_SCRIPT, "idle.py");
                }
 
                fff = my_fopen(buf, "rw");
@@ -110,7 +110,7 @@ errr init_script(void)
        ascii_to_text(path, ANGBAND_DIR_SCRIPT);
 
        /* Build the path to the Python modules */
-       path_build(buf, 1024, ANGBAND_DIR_SCRIPT, "python");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_SCRIPT, "python");
 
        /* Convert the script path to a nice string */
        ascii_to_text(path1, buf);
index 222cd42..bb181e9 100644 (file)
@@ -3314,28 +3314,12 @@ bool get_check_strict(cptr prompt, int mode)
        /* Hack -- Build a "useful" prompt */
        if (mode & CHECK_OKAY_CANCEL)
        {
-#ifdef JP
-               /* (79-8)¥Ð¥¤¥È¤Î»ØÄê, prompt¤¬Ä¹¤«¤Ã¤¿¾ì¹ç, 
-                  (79-9)ʸ»ú¤Î¸å½ªÃ¼Ê¸»ú¤¬½ñ¤­¹þ¤Þ¤ì¤ë.     
-                  ±Ñ¸ì¤ÎÊý¤Îstrncpy¤È¤Ï°ã¤¦¤Î¤ÇÃí°Õ.
-                  else¤ÎÊý¤Îʬ´ô¤âƱÍÍ. --henkma
-               */
-               mb_strlcpy(buf, prompt, 80-15);
-#else
-               strncpy(buf, prompt, 79-15);
-               buf[79-8]='\0';
-#endif
+               my_strcpy(buf, prompt, sizeof(buf)-15);
                strcat(buf, "[(O)k/(C)ancel]");
-
        }
        else
        {
-#ifdef JP
-               mb_strlcpy(buf, prompt, 80-5);
-#else
-               strncpy(buf, prompt, 79-5);
-               buf[79-5]='\0';
-#endif
+               my_strcpy(buf, prompt, sizeof(buf)-5);
                strcat(buf, "[y/n]");
        }
 
@@ -4910,3 +4894,95 @@ void roff_to_buf(cptr str, int maxlen, char *tbuf)
        return;
 }
 
+
+/*
+ * The my_strcpy() function copies up to 'bufsize'-1 characters from 'src'
+ * to 'buf' and NUL-terminates the result.  The 'buf' and 'src' strings may
+ * not overlap.
+ *
+ * my_strcpy() returns strlen(src).  This makes checking for truncation
+ * easy.  Example: if (my_strcpy(buf, src, sizeof(buf)) >= sizeof(buf)) ...;
+ *
+ * This function should be equivalent to the strlcpy() function in BSD.
+ */
+size_t my_strcpy(char *buf, const char *src, size_t bufsize)
+{
+#ifdef JP
+
+       char *d = buf;
+       const char *s = src;
+       size_t len = 0;
+
+       /* reserve for NUL termination */
+       bufsize--;
+
+       /* Copy as many bytes as will fit */
+       while (len < bufsize)
+        {
+               if (iskanji(*s))
+                {
+                       if (len + 1 >= bufsize || !*(s+1)) break;
+                       *d++ = *s++;
+                       *d++ = *s++;
+                       len += 2;
+               }
+                else
+                {
+                       *d++ = *s++;
+                       len++;
+               }
+       }
+       *d = '\0';
+       while(*s++) len++;
+
+       return len;
+
+#else
+
+       size_t len = strlen(src);
+       size_t ret = len;
+
+       /* Paranoia */
+       if (bufsize == 0) return ret;
+
+       /* Truncate */
+       if (len >= bufsize) len = bufsize - 1;
+
+       /* Copy the string and terminate it */
+       (void)memcpy(buf, src, len);
+       buf[len] = '\0';
+
+       /* Return strlen(src) */
+       return ret;
+
+#endif
+}
+
+
+/*
+ * The my_strcat() tries to append a string to an existing NUL-terminated string.
+ * It never writes more characters into the buffer than indicated by 'bufsize' and
+ * NUL-terminates the buffer.  The 'buf' and 'src' strings may not overlap.
+ *
+ * my_strcat() returns strlen(buf) + strlen(src).  This makes checking for
+ * truncation easy.  Example:
+ * if (my_strcat(buf, src, sizeof(buf)) >= sizeof(buf)) ...;
+ *
+ * This function should be equivalent to the strlcat() function in BSD.
+ */
+size_t my_strcat(char *buf, const char *src, size_t bufsize)
+{
+       size_t dlen = strlen(buf);
+
+       /* Is there room left in the buffer? */
+       if (dlen < bufsize - 1)
+       {
+               /* Append as much as possible  */
+               return (dlen + my_strcpy(buf + dlen, src, bufsize - dlen));
+       }
+       else
+       {
+               /* Return without appending */
+               return (dlen + strlen(src));
+       }
+}
index a1fdd82..c416259 100644 (file)
@@ -357,7 +357,7 @@ static void spoil_obj_desc(cptr fname)
 
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_USER, fname);
+       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
 
        /* File type is "TEXT" */
        FILE_TYPE(FILE_TYPE_TEXT);
@@ -1572,7 +1572,7 @@ static void spoil_artifact(cptr fname)
 
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_USER, fname);
+       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
 
        /* File type is "TEXT" */
        FILE_TYPE(FILE_TYPE_TEXT);
@@ -1662,7 +1662,7 @@ static void spoil_mon_desc(cptr fname)
        char exp[80];
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_USER, fname);
+       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
 
        /* File type is "TEXT" */
        FILE_TYPE(FILE_TYPE_TEXT);
@@ -1942,7 +1942,7 @@ static void spoil_mon_info(cptr fname)
        s16b *who;
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_USER, fname);
+       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
 
        /* File type is "TEXT" */
        FILE_TYPE(FILE_TYPE_TEXT);
@@ -2326,7 +2326,7 @@ void spoil_random_artifact(cptr fname)
        safe_setuid_drop();
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_USER, fname);
+       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
 
        /* File type is "TEXT" */
        FILE_TYPE(FILE_TYPE_TEXT);
index 5ef97a8..050ae36 100644 (file)
@@ -691,12 +691,7 @@ static void prt_title(void)
        /* Normal */
        else
        {
-#ifdef JP
-               mb_strlcpy(str, player_title[p_ptr->pclass][(p_ptr->lev - 1) / 5], 14);
-#else
-               strncpy(str, player_title[p_ptr->pclass][(p_ptr->lev - 1) / 5], 13);
-               str[13] = '\0';
-#endif
+               my_strcpy(str, player_title[p_ptr->pclass][(p_ptr->lev - 1) / 5], sizeof(str));
                p = str;
        }
 
@@ -1649,13 +1644,9 @@ static void prt_frame_basic(void)
                prt_field(mimic_info[p_ptr->mimic_form].title, ROW_RACE, COL_RACE);
        else
        {
-#ifdef JP
                char str[14];
-               mb_strlcpy(str, rp_ptr->title, 14);
+               my_strcpy(str, rp_ptr->title, sizeof(str));
                prt_field(str, ROW_RACE, COL_RACE);
-#else
-               prt_field(rp_ptr->title, ROW_RACE, COL_RACE);
-#endif
        }
 /*     prt_field(cp_ptr->title, ROW_CLASS, COL_CLASS); */
 /*     prt_field(ap_ptr->title, ROW_SEIKAKU, COL_SEIKAKU); */
index 4b97a10..e3ded43 100644 (file)
 #include "z-util.h"
 
 
-
-/*
- * Global variables for temporary use
- */
-char char_tmp = 0;
-byte byte_tmp = 0;
-sint sint_tmp = 0;
-uint uint_tmp = 0;
-long long_tmp = 0;
-huge huge_tmp = 0;
-errr errr_tmp = 0;
-
-
-/*
- * Global pointers for temporary use
- */
-cptr cptr_tmp = NULL;
-vptr vptr_tmp = NULL;
-
-
-
-
-/*
- * Constant bool meaning true
- */
-bool bool_true = 1;
-
-/*
- * Constant bool meaning false
- */
-bool bool_false = 0;
-
-
-/*
- * Global NULL cptr
- */
-cptr cptr_null = NULL;
-
-
-/*
- * Global NULL vptr
- */
-vptr vptr_null = NULL;
-
-
-
-/*
- * Global SELF vptr
- */
-vptr vptr_self = (vptr)(&vptr_self);
-
-
-
 /*
  * Convenient storage of the program name
  */
 cptr argv0 = NULL;
 
 
-
-/*
- * A routine that does nothing
- */
-void func_nothing(void)
-{
-       /* Do nothing */
-}
-
-
-/*
- * A routine that always returns "success"
- */
-errr func_success(void)
-{
-       return (0);
-}
-
-
-/*
- * A routine that always returns a simple "problem code"
- */
-errr func_problem(void)
-{
-       return (1);
-}
-
-
-/*
- * A routine that always returns a simple "failure code"
- */
-errr func_failure(void)
-{
-       return (-1);
-}
-
-
-
-/*
- * A routine that always returns "true"
- */
-bool func_true(void)
-{
-       return (1);
-}
-
-
-/*
- * A routine that always returns "false"
- */
-bool func_false(void)
-{
-       return (0);
-}
-
-
-
-
 /*
  * Determine if string "t" is equal to string "t"
  */
index 64871cf..f90c74f 100644 (file)
 
 /**** Available variables ****/
 
-/* Temporary Vars */
-extern char char_tmp;
-extern byte byte_tmp;
-extern sint sint_tmp;
-extern uint uint_tmp;
-extern long long_tmp;
-extern huge huge_tmp;
-extern errr errr_tmp;
-
-/* Temporary Pointers */
-extern cptr cptr_tmp;
-extern vptr vptr_tmp;
-
-
-/* Constant pointers (NULL) */
-extern cptr cptr_null;
-extern vptr vptr_null;
-
-
-/* A bizarre vptr that always points at itself */
-extern vptr vptr_self;
-
-
 /* A cptr to the name of the program */
 extern cptr argv0;
 
@@ -50,19 +27,6 @@ extern void (*core_aux)(cptr);
 
 /**** Available Functions ****/
 
-/* Function that does nothing */
-extern void func_nothing(void);
-
-/* Functions that return basic "errr" codes */
-extern errr func_success(void);
-extern errr func_problem(void);
-extern errr func_failure(void);
-
-/* Functions that return bools */
-extern bool func_true(void);
-extern bool func_false(void);
-
-
 /* Test equality, prefix, suffix */
 extern bool streq(cptr s, cptr t);
 extern bool prefix(cptr s, cptr t);