diff -Paur --no-dereference -- gettext.upstream/gettext-runtime/configure gettext/gettext-runtime/configure
--- gettext.upstream/gettext-runtime/configure
+++ gettext/gettext-runtime/configure
@@ -1,4 +1,124 @@
 #! /bin/sh
+# Make gnulib assume the best about unknown operating systems when cross-compiling.
+export ac_cv_func_calloc_0_nonnull=yes
+export ac_cv_func_chown_works=yes
+export ac_cv_func_getgroups_works=yes
+export ac_cv_func_malloc_0_nonnull=yes
+export gl_cv_func_cbrtl_ieee=yes
+export gl_cv_func_ceilf_ieee=yes
+export gl_cv_func_ceil_ieee=yes
+export gl_cv_func_ceill_ieee=yes
+export gl_cv_func_chown_ctime_works=yes
+export gl_cv_func_chown_slash_works=yes
+export gl_cv_func_exp2l_ieee=yes
+export gl_cv_func_expm1_ieee=yes
+export gl_cv_func_fcntl_f_dupfd_works=yes # Not needed since February 2015
+export gl_cv_func_fdopendir_works=yes
+export gl_cv_func_floorf_ieee=yes
+export gl_cv_func_fmaf_works=yes
+export gl_cv_func_fmal_works=yes
+export gl_cv_func_fma_works=yes
+export gl_cv_func_fmodf_ieee=yes
+export gl_cv_func_fmod_ieee=yes
+export gl_cv_func_fmodl_ieee=yes
+export gl_cv_func_fpurge_works=yes
+export gl_cv_func_futimens_works=yes
+export gl_cv_func_futimesat_works=yes
+export gl_cv_func_getgroups_works=yes
+export gl_cv_func_gettimeofday_clobber=no
+export gl_cv_func_hypotf_ieee=yes
+export gl_cv_func_hypotl_ieee=yes
+export gl_cv_func_hypot_ieee=yes
+export gl_cv_func_isfinitel_works=yes
+export gl_cv_func_isnanl_works=yes
+export gl_cv_func_linkat_slash=yes
+export gl_cv_func_link_works=yes
+export gl_cv_func_log10f_ieee=yes
+export gl_cv_func_log10_ieee=yes
+export gl_cv_func_log1pf_ieee=yes
+export gl_cv_func_log1p_ieee=yes
+export gl_cv_func_log1pl_ieee=yes
+export gl_cv_func_log2f_ieee=yes
+export gl_cv_func_log2_ieee=yes
+export gl_cv_func_logf_ieee=yes
+export gl_cv_func_log_ieee=yes
+export gl_cv_func_lstat_dereferences_slashed_symlink=yes
+export gl_cv_func_mbrlen_empty_input=yes
+export gl_cv_func_mbrtowc_empty_input=yes
+export gl_cv_func_memchr_works=yes
+export gl_cv_func_memmem_works_fast=yes
+export gl_cv_func_mkdir_trailing_dot_works=yes
+export gl_cv_func_mkdir_trailing_slash_works=yes
+export gl_cv_func_mkfifo_works=yes
+export gl_cv_func_mknod_works=yes
+export gl_cv_func_modff_ieee=yes
+export gl_cv_func_modf_ieee=yes
+export gl_cv_func_modfl_ieee=yes
+export gl_cv_func_nanosleep=yes
+export gl_cv_func_open_directory_works=yes
+export gl_cv_func_perror_works=yes
+export gl_cv_func_printf_directive_a=yes
+export gl_cv_func_printf_directive_f=yes
+export gl_cv_func_printf_directive_n=yes
+export gl_cv_func_printf_enomem=yes
+export gl_cv_func_printf_flag_zero=yes
+export gl_cv_func_printf_infinite_long_double=yes
+export gl_cv_func_printf_infinite=yes
+export gl_cv_func_printf_sizes_c99=yes
+export gl_cv_func_pselect_detects_ebadf=yes
+export gl_cv_func_ptsname_sets_errno=yes
+export gl_cv_func_readlink_works=yes
+export gl_cv_func_realpath_works=yes
+export gl_cv_func_remainderf_ieee=yes
+export gl_cv_func_remainder_ieee=yes
+export gl_cv_func_remainderl_ieee=yes
+export gl_cv_func_rename_dest_works=yes
+export gl_cv_func_rename_link_works=yes
+export gl_cv_func_rename_slash_dst_works=yes
+export gl_cv_func_rename_slash_src_works=yes
+export gl_cv_func_rmdir_works=yes
+export gl_cv_func_roundf_ieee=yes
+export gl_cv_func_round_ieee=yes
+export gl_cv_func_select_detects_ebadf=yes
+export gl_cv_func_setenv_works=yes
+export gl_cv_func_signbit_gcc=yes
+export gl_cv_func_signbit=yes
+export gl_cv_func_sleep_works=yes
+export gl_cv_func_snprintf_directive_n=yes
+export gl_cv_func_snprintf_retval_c99=yes
+export gl_cv_func_snprintf_truncation_c99=yes
+export gl_cv_func_stat_dir_slash=yes
+export gl_cv_func_stat_file_slash=yes
+export gl_cv_func_stpncpy=yes
+export gl_cv_func_strcasestr_linear=yes
+export gl_cv_func_strchrnul_works=yes
+export gl_cv_func_strerror_0_works=yes
+export gl_cv_func_strstr_linear=yes
+export gl_cv_func_strtod_works=yes
+export gl_cv_func_svid_putenv=yes
+export gl_cv_func_symlink_works=yes
+export gl_cv_func_tdelete_works=yes
+export gl_cv_func_truncf_ieee=yes
+export gl_cv_func_trunc_ieee=yes
+export gl_cv_func_truncl_ieee=yes
+export gl_cv_func_tzset_clobber=no
+export gl_cv_func_ungetc_works=yes
+export gl_cv_func_unlink_honors_slashes=yes
+export gl_cv_func_unsetenv_works=yes
+export gl_cv_func_usleep_works=yes
+export gl_cv_func_utimensat_works=yes
+export gl_cv_func_vsnprintf_posix=yes
+export gl_cv_func_vsnprintf_zerosize_c99=yes
+export gl_cv_func_vsprintf_posix=yes
+export gl_cv_func_wcwidth_works=yes
+export gl_cv_func_working_getdelim=yes
+export gl_cv_func_working_mkstemp=yes
+export gl_cv_func_working_mktime=yes
+export gl_cv_func_working_strerror=yes
+export ac_cv_func___fseterr=yes # Only if the OS actually supports this, Sortix does.
+export gl_cv_func_getcwd_null=yes # Only if the OS actually supports this, Sortix does.
+export gl_cv_struct_dirent_d_ino=yes # Only if the OS actually supports this, Sortix does.
+export ac_cv_func_realloc_0_nonnull=yes # TODO: Investigate this, found in flex.
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.69 for gettext-runtime 0.21.
 #
@@ -20509,6 +20629,8 @@
 static char buf[100];
 int main ()
 {
+  /* PATCH: Never replace Sortix printf even if it doesn't have this feature. */
+  return 0;
   sprintf (buf, format, 33, 55);
   return (strcmp (buf, "55 33") != 0);
 }
diff -Paur --no-dereference -- gettext.upstream/gettext-runtime/gnulib-lib/propername.c gettext/gettext-runtime/gnulib-lib/propername.c
--- gettext.upstream/gettext-runtime/gnulib-lib/propername.c
+++ gettext/gettext-runtime/gnulib-lib/propername.c
@@ -168,10 +168,10 @@
       else
         {
           /* Return "TRANSLATION (NAME)".  */
-          char *result =
-            XNMALLOC (strlen (translation) + 2 + strlen (name) + 1 + 1, char);
+          size_t size = strlen (translation) + 2 + strlen (name) + 1 + 1;
+          char *result = XNMALLOC (size, char);
 
-          sprintf (result, "%s (%s)", translation, name);
+          snprintf (result, size, "%s (%s)", translation, name);
           return result;
         }
     }
@@ -270,10 +270,10 @@
       else
         {
           /* Return "TRANSLATION (NAME)".  */
-          char *result =
-            XNMALLOC (strlen (translation) + 2 + strlen (name) + 1 + 1, char);
+          size_t size = strlen (translation) + 2 + strlen (name) + 1 + 1;
+          char *result = XNMALLOC (size, char);
 
-          sprintf (result, "%s (%s)", translation, name);
+          snprintf (result, size, "%s (%s)", translation, name);
 
           if (alloc_name_converted != NULL)
             free (alloc_name_converted);
diff -Paur --no-dereference -- gettext.upstream/gettext-runtime/intl/dcigettext.c gettext/gettext-runtime/intl/dcigettext.c
--- gettext.upstream/gettext-runtime/intl/dcigettext.c
+++ gettext/gettext-runtime/intl/dcigettext.c
@@ -1069,6 +1069,8 @@
       resultlen = domain->trans_sysdep_tab[act - nstrings].length;
     }
 
+#if 0 /* PATCH: Disable iconv dependency to produce smaller programs.  With luck
+         anything that matters at this time is already UTF-8. */
 #if defined _LIBC || HAVE_ICONV
 # ifdef IN_LIBGLOCALE
   if (encoding != NULL)
@@ -1475,6 +1477,7 @@
   /* The result string is converted.  */
 
 #endif /* _LIBC || HAVE_ICONV */
+#endif
 
   *lengthp = resultlen;
   return result;
diff -Paur --no-dereference -- gettext.upstream/gettext-runtime/libasprintf/configure gettext/gettext-runtime/libasprintf/configure
--- gettext.upstream/gettext-runtime/libasprintf/configure
+++ gettext/gettext-runtime/libasprintf/configure
@@ -19342,6 +19342,8 @@
 static char buf[100];
 int main ()
 {
+  /* PATCH: Never replace Sortix printf even if it doesn't have this feature. */
+  return 0;
   sprintf (buf, format, 33, 55);
   return (strcmp (buf, "55 33") != 0);
 }
diff -Paur --no-dereference -- gettext.upstream/gettext-tools/configure gettext/gettext-tools/configure
--- gettext.upstream/gettext-tools/configure
+++ gettext/gettext-tools/configure
@@ -1,4 +1,124 @@
 #! /bin/sh
+# Make gnulib assume the best about unknown operating systems when cross-compiling.
+export ac_cv_func_calloc_0_nonnull=yes
+export ac_cv_func_chown_works=yes
+export ac_cv_func_getgroups_works=yes
+export ac_cv_func_malloc_0_nonnull=yes
+export gl_cv_func_cbrtl_ieee=yes
+export gl_cv_func_ceilf_ieee=yes
+export gl_cv_func_ceil_ieee=yes
+export gl_cv_func_ceill_ieee=yes
+export gl_cv_func_chown_ctime_works=yes
+export gl_cv_func_chown_slash_works=yes
+export gl_cv_func_exp2l_ieee=yes
+export gl_cv_func_expm1_ieee=yes
+export gl_cv_func_fcntl_f_dupfd_works=yes # Not needed since February 2015
+export gl_cv_func_fdopendir_works=yes
+export gl_cv_func_floorf_ieee=yes
+export gl_cv_func_fmaf_works=yes
+export gl_cv_func_fmal_works=yes
+export gl_cv_func_fma_works=yes
+export gl_cv_func_fmodf_ieee=yes
+export gl_cv_func_fmod_ieee=yes
+export gl_cv_func_fmodl_ieee=yes
+export gl_cv_func_fpurge_works=yes
+export gl_cv_func_futimens_works=yes
+export gl_cv_func_futimesat_works=yes
+export gl_cv_func_getgroups_works=yes
+export gl_cv_func_gettimeofday_clobber=no
+export gl_cv_func_hypotf_ieee=yes
+export gl_cv_func_hypotl_ieee=yes
+export gl_cv_func_hypot_ieee=yes
+export gl_cv_func_isfinitel_works=yes
+export gl_cv_func_isnanl_works=yes
+export gl_cv_func_linkat_slash=yes
+export gl_cv_func_link_works=yes
+export gl_cv_func_log10f_ieee=yes
+export gl_cv_func_log10_ieee=yes
+export gl_cv_func_log1pf_ieee=yes
+export gl_cv_func_log1p_ieee=yes
+export gl_cv_func_log1pl_ieee=yes
+export gl_cv_func_log2f_ieee=yes
+export gl_cv_func_log2_ieee=yes
+export gl_cv_func_logf_ieee=yes
+export gl_cv_func_log_ieee=yes
+export gl_cv_func_lstat_dereferences_slashed_symlink=yes
+export gl_cv_func_mbrlen_empty_input=yes
+export gl_cv_func_mbrtowc_empty_input=yes
+export gl_cv_func_memchr_works=yes
+export gl_cv_func_memmem_works_fast=yes
+export gl_cv_func_mkdir_trailing_dot_works=yes
+export gl_cv_func_mkdir_trailing_slash_works=yes
+export gl_cv_func_mkfifo_works=yes
+export gl_cv_func_mknod_works=yes
+export gl_cv_func_modff_ieee=yes
+export gl_cv_func_modf_ieee=yes
+export gl_cv_func_modfl_ieee=yes
+export gl_cv_func_nanosleep=yes
+export gl_cv_func_open_directory_works=yes
+export gl_cv_func_perror_works=yes
+export gl_cv_func_printf_directive_a=yes
+export gl_cv_func_printf_directive_f=yes
+export gl_cv_func_printf_directive_n=yes
+export gl_cv_func_printf_enomem=yes
+export gl_cv_func_printf_flag_zero=yes
+export gl_cv_func_printf_infinite_long_double=yes
+export gl_cv_func_printf_infinite=yes
+export gl_cv_func_printf_sizes_c99=yes
+export gl_cv_func_pselect_detects_ebadf=yes
+export gl_cv_func_ptsname_sets_errno=yes
+export gl_cv_func_readlink_works=yes
+export gl_cv_func_realpath_works=yes
+export gl_cv_func_remainderf_ieee=yes
+export gl_cv_func_remainder_ieee=yes
+export gl_cv_func_remainderl_ieee=yes
+export gl_cv_func_rename_dest_works=yes
+export gl_cv_func_rename_link_works=yes
+export gl_cv_func_rename_slash_dst_works=yes
+export gl_cv_func_rename_slash_src_works=yes
+export gl_cv_func_rmdir_works=yes
+export gl_cv_func_roundf_ieee=yes
+export gl_cv_func_round_ieee=yes
+export gl_cv_func_select_detects_ebadf=yes
+export gl_cv_func_setenv_works=yes
+export gl_cv_func_signbit_gcc=yes
+export gl_cv_func_signbit=yes
+export gl_cv_func_sleep_works=yes
+export gl_cv_func_snprintf_directive_n=yes
+export gl_cv_func_snprintf_retval_c99=yes
+export gl_cv_func_snprintf_truncation_c99=yes
+export gl_cv_func_stat_dir_slash=yes
+export gl_cv_func_stat_file_slash=yes
+export gl_cv_func_stpncpy=yes
+export gl_cv_func_strcasestr_linear=yes
+export gl_cv_func_strchrnul_works=yes
+export gl_cv_func_strerror_0_works=yes
+export gl_cv_func_strstr_linear=yes
+export gl_cv_func_strtod_works=yes
+export gl_cv_func_svid_putenv=yes
+export gl_cv_func_symlink_works=yes
+export gl_cv_func_tdelete_works=yes
+export gl_cv_func_truncf_ieee=yes
+export gl_cv_func_trunc_ieee=yes
+export gl_cv_func_truncl_ieee=yes
+export gl_cv_func_tzset_clobber=no
+export gl_cv_func_ungetc_works=yes
+export gl_cv_func_unlink_honors_slashes=yes
+export gl_cv_func_unsetenv_works=yes
+export gl_cv_func_usleep_works=yes
+export gl_cv_func_utimensat_works=yes
+export gl_cv_func_vsnprintf_posix=yes
+export gl_cv_func_vsnprintf_zerosize_c99=yes
+export gl_cv_func_vsprintf_posix=yes
+export gl_cv_func_wcwidth_works=yes
+export gl_cv_func_working_getdelim=yes
+export gl_cv_func_working_mkstemp=yes
+export gl_cv_func_working_mktime=yes
+export gl_cv_func_working_strerror=yes
+export ac_cv_func___fseterr=yes # Only if the OS actually supports this, Sortix does.
+export gl_cv_func_getcwd_null=yes # Only if the OS actually supports this, Sortix does.
+export gl_cv_struct_dirent_d_ino=yes # Only if the OS actually supports this, Sortix does.
+export ac_cv_func_realloc_0_nonnull=yes # TODO: Investigate this, found in flex.
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.69 for gettext-tools 0.21.
 #
@@ -22666,6 +22786,8 @@
 static char buf[100];
 int main ()
 {
+  /* PATCH: Never replace Sortix printf even if it doesn't have this feature. */
+  return 0;
   sprintf (buf, format, 33, 55);
   return (strcmp (buf, "55 33") != 0);
 }
@@ -24410,10 +24532,10 @@
 $as_echo "$ac_res" >&6; }
         fi
 
+           # PATCH: Use preinstalled libintl in gettext-tools.
                                         if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" = "yes"; } \
            || { { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; } \
-                && test "$PACKAGE" != gettext-runtime \
-                && test "$PACKAGE" != gettext-tools; }; then
+                && test "$PACKAGE" != gettext-runtime; }; then
           gt_use_preinstalled_gnugettext=yes
         else
                     LIBINTL=
@@ -46687,7 +46809,9 @@
 
 
 
-    use_additional=yes
+    # PATCH: It's just plain wrong to search for libxml2 in the prefix rather
+    #        than using the pkg-config, or at least using the system root.
+    use_additional=no
 
   acl_save_prefix="$prefix"
   prefix="$acl_final_prefix"
@@ -46709,6 +46833,7 @@
     if test "X$withval" = "Xno"; then
       use_additional=no
     else
+      use_additional=yes
       if test "X$withval" = "X"; then
 
   acl_save_prefix="$prefix"
@@ -54326,6 +54451,8 @@
 static char buf[100];
 int main ()
 {
+  /* PATCH: Never replace Sortix printf even if it doesn't have this feature. */
+  return 0;
   sprintf (buf, format, 33, 55);
   return (strcmp (buf, "55 33") != 0);
 }
@@ -58358,6 +58485,8 @@
 static char buf[100];
 int main ()
 {
+  /* PATCH: Never replace Sortix printf even if it doesn't have this feature. */
+  return 0;
   sprintf (buf, format, 33, 55);
   return (strcmp (buf, "55 33") != 0);
 }
diff -Paur --no-dereference -- gettext.upstream/gettext-tools/gnulib-lib/backupfile.c gettext/gettext-tools/gnulib-lib/backupfile.c
--- gettext.upstream/gettext-tools/gnulib-lib/backupfile.c
+++ gettext/gettext-tools/gnulib-lib/backupfile.c
@@ -89,14 +89,15 @@
   size_t numbered_suffix_size_max = INT_STRLEN_BOUND (int) + 4;
   char *s;
   const char *suffix = simple_backup_suffix;
+  size_t ssize;
 
   /* Allow room for simple or '.~N~' backups.  */
   backup_suffix_size_max = strlen (simple_backup_suffix) + 1;
   if (HAVE_DIR && backup_suffix_size_max < numbered_suffix_size_max)
     backup_suffix_size_max = numbered_suffix_size_max;
 
-  s = (char *) malloc (file_len + backup_suffix_size_max
-                       + numbered_suffix_size_max);
+  ssize = file_len + backup_suffix_size_max + numbered_suffix_size_max;
+  s = (char *) malloc (ssize);
   if (s)
     {
       strcpy (s, file);
@@ -111,8 +112,10 @@
           highest_backup = max_backup_version (file + dir_len, s);
           if (! (backup_type == numbered_existing && highest_backup == 0))
             {
-              char *numbered_suffix = s + (file_len + backup_suffix_size_max);
-              sprintf (numbered_suffix, ".~%d~", highest_backup + 1);
+              size_t off = file_len + backup_suffix_size_max;
+              size_t rem = ssize - off;
+              char *numbered_suffix = s + off;
+              snprintf (numbered_suffix, rem, ".~%d~", highest_backup + 1);
               suffix = numbered_suffix;
             }
           strcpy (s, file);
diff -Paur --no-dereference -- gettext.upstream/gettext-tools/gnulib-lib/propername.c gettext/gettext-tools/gnulib-lib/propername.c
--- gettext.upstream/gettext-tools/gnulib-lib/propername.c
+++ gettext/gettext-tools/gnulib-lib/propername.c
@@ -168,10 +168,10 @@
       else
         {
           /* Return "TRANSLATION (NAME)".  */
-          char *result =
-            XNMALLOC (strlen (translation) + 2 + strlen (name) + 1 + 1, char);
+          size_t size = strlen (translation) + 2 + strlen (name) + 1 + 1;
+          char *result = XNMALLOC (size, char);
 
-          sprintf (result, "%s (%s)", translation, name);
+          snprintf (result, size, "%s (%s)", translation, name);
           return result;
         }
     }
@@ -270,10 +270,10 @@
       else
         {
           /* Return "TRANSLATION (NAME)".  */
-          char *result =
-            XNMALLOC (strlen (translation) + 2 + strlen (name) + 1 + 1, char);
+          size_t size = strlen (translation) + 2 + strlen (name) + 1 + 1;
+          char *result = XNMALLOC (size, char);
 
-          sprintf (result, "%s (%s)", translation, name);
+          snprintf (result, size, "%s (%s)", translation, name);
 
           if (alloc_name_converted != NULL)
             free (alloc_name_converted);
diff -Paur --no-dereference -- gettext.upstream/gettext-tools/gnulib-lib/tmpdir.c gettext/gettext-tools/gnulib-lib/tmpdir.c
--- gettext.upstream/gettext-tools/gnulib-lib/tmpdir.c
+++ gettext/gettext-tools/gnulib-lib/tmpdir.c
@@ -160,6 +160,7 @@
     }
 
   memcpy (tmpl, dir, dlen);
-  sprintf (tmpl + dlen, &"/%.*sXXXXXX"[!add_slash], (int) plen, pfx);
+  snprintf (tmpl + dlen, 1 + tmpl_len - dlen, &"/%.*sXXXXXX"[!add_slash],
+            (int) plen, pfx);
   return 0;
 }
diff -Paur --no-dereference -- gettext.upstream/gettext-tools/gnulib-lib/uniname/uniname.c gettext/gettext-tools/gnulib-lib/uniname/uniname.c
--- gettext.upstream/gettext-tools/gnulib-lib/uniname/uniname.c
+++ gettext/gettext-tools/gnulib-lib/uniname/uniname.c
@@ -286,8 +286,8 @@
          small.  */
 
       /* buf needs to have at least 19 + 3 bytes here.  */
-      sprintf (buf, "VARIATION SELECTOR-%d",
-               c <= 0xFE0F ? c - 0xFE00 + 1 : c - 0xE0100 + 17);
+      snprintf (buf, UNINAME_MAX, "VARIATION SELECTOR-%d",
+                c <= 0xFE0F ? c - 0xFE00 + 1 : c - 0xE0100 + 17);
       return buf;
     }
   else
diff -Paur --no-dereference -- gettext.upstream/gettext-tools/src/cldr-plurals.c gettext/gettext-tools/src/cldr-plurals.c
--- gettext.upstream/gettext-tools/src/cldr-plurals.c
+++ gettext/gettext-tools/src/cldr-plurals.c
@@ -159,7 +159,7 @@
               buffer = (char *) xrealloc (buffer, bufmax);
             }
 
-          sprintf (buffer + buflen, "%s: %s; ", count, content);
+          snprintf (buffer + buflen, bufmax - buflen, "%s: %s; ", count, content);
           xmlFree (count);
           xmlFree (content);
 
diff -Paur --no-dereference -- gettext.upstream/gettext-tools/src/format.c gettext/gettext-tools/src/format.c
--- gettext.upstream/gettext-tools/src/format.c
+++ gettext/gettext-tools/src/format.c
@@ -112,7 +112,7 @@
 
           if (msgid_plural != NULL)
             {
-              sprintf (buf, "msgstr[%u]", j);
+              snprintf (buf, sizeof(buf), "msgstr[%u]", j);
               pretty_msgstr = buf;
             }
 
diff -Paur --no-dereference -- gettext.upstream/gettext-tools/src/read-mo.c gettext/gettext-tools/src/read-mo.c
--- gettext.upstream/gettext-tools/src/read-mo.c
+++ gettext/gettext-tools/src/read-mo.c
@@ -193,7 +193,8 @@
       if (!(ss_length > 0 && bfp->data[ss_end - 1] == '\0'))
         {
           char location[30];
-          sprintf (location, "sysdep_segment[%u]", (unsigned int) sysdepref);
+          snprintf (location, sizeof (location),
+                    "sysdep_segment[%u]", (unsigned int) sysdepref);
           error (EXIT_FAILURE, 0,
                  _("file \"%s\" contains a not NUL terminated string, at %s"),
                  bfp->filename, location);
diff -Paur --no-dereference -- gettext.upstream/gettext-tools/src/write-csharp.c gettext/gettext-tools/src/write-csharp.c
--- gettext.upstream/gettext-tools/src/write-csharp.c
+++ gettext/gettext-tools/src/write-csharp.c
@@ -721,10 +721,10 @@
   {
     char *class_name_part1 = construct_class_name (resource_name);
     char *p;
+    size_t size = strlen (class_name_part1) + 1 + strlen (culture_name) + 1;
 
-    class_name =
-      XNMALLOC (strlen (class_name_part1) + 1 + strlen (culture_name) + 1, char);
-    sprintf (class_name, "%s_%s", class_name_part1, culture_name);
+    class_name = XNMALLOC (size, char);
+    snprintf (class_name, size, "%s_%s", class_name_part1, culture_name);
     for (p = class_name + strlen (class_name_part1) + 1; *p != '\0'; p++)
       if (*p == '-')
         *p = '_';
diff -Paur --no-dereference -- gettext.upstream/gettext-tools/src/write-po.c gettext/gettext-tools/src/write-po.c
--- gettext.upstream/gettext-tools/src/write-po.c
+++ gettext/gettext-tools/src/write-po.c
@@ -76,16 +76,16 @@
     case possible:
       if (debug)
         {
-          sprintf (result, "possible-%s-format", lang);
+          snprintf (result, sizeof(result), "possible-%s-format", lang);
           break;
         }
       /* FALLTHROUGH */
     case yes_according_to_context:
     case yes:
-      sprintf (result, "%s-format", lang);
+      snprintf (result, sizeof(result), "%s-format", lang);
       break;
     case no:
-      sprintf (result, "no-%s-format", lang);
+      snprintf (result, sizeof(result), "no-%s-format", lang);
       break;
     default:
       /* The others have already been filtered out by significant_format_p.  */
@@ -398,7 +398,7 @@
                   || pp->line_number == (size_t)(-1))
                 buffer[0] = '\0';
               else
-                sprintf (buffer, ":%ld", (long) pp->line_number);
+                snprintf (buffer, sizeof (buffer), ":%ld", (long) pp->line_number);
               len = strlen (cp) + strlen (buffer) + 1;
               if (column > 2 && column + len > page_width)
                 {
@@ -1373,7 +1373,7 @@
            p < mp->msgstr + mp->msgstr_len;
            p += strlen (p) + 1, i++)
         {
-          sprintf (prefix_buf, "msgstr[%u]", i);
+          snprintf (prefix_buf, sizeof (prefix_buf), "msgstr[%u]", i);
           wrap (mp, stream, NULL, extra_indent, class_msgstr, prefix_buf, p,
                 mp->do_wrap, page_width, charset);
         }
@@ -1541,7 +1541,7 @@
            p < mp->msgstr + mp->msgstr_len;
            p += strlen (p) + 1, i++)
         {
-          sprintf (prefix_buf, "msgstr[%u]", i);
+          snprintf (prefix_buf, sizeof (prefix_buf), "msgstr[%u]", i);
           wrap (mp, stream, "#~ ", extra_indent, class_msgstr, prefix_buf, p,
                 mp->do_wrap, page_width, charset);
         }
diff -Paur --no-dereference -- gettext.upstream/gettext-tools/src/write-properties.c gettext/gettext-tools/src/write-properties.c
--- gettext.upstream/gettext-tools/src/write-properties.c
+++ gettext/gettext-tools/src/write-properties.c
@@ -97,7 +97,7 @@
         else if (uc < 0x10000)
           {
             /* Single UCS-2 'char'  */
-            sprintf (newstr, "\\u%c%c%c%c",
+            snprintf (newstr, length + 1 - (newstr - result), "\\u%c%c%c%c",
                      hexdigit[(uc >> 12) & 0x0f], hexdigit[(uc >> 8) & 0x0f],
                      hexdigit[(uc >> 4) & 0x0f], hexdigit[uc & 0x0f]);
             newstr += 6;
@@ -107,11 +107,11 @@
             /* UTF-16 surrogate: two 'char's.  */
             ucs4_t uc1 = 0xd800 + ((uc - 0x10000) >> 10);
             ucs4_t uc2 = 0xdc00 + ((uc - 0x10000) & 0x3ff);
-            sprintf (newstr, "\\u%c%c%c%c",
+            snprintf (newstr, length + 1 - (newstr - result), "\\u%c%c%c%c",
                      hexdigit[(uc1 >> 12) & 0x0f], hexdigit[(uc1 >> 8) & 0x0f],
                      hexdigit[(uc1 >> 4) & 0x0f], hexdigit[uc1 & 0x0f]);
             newstr += 6;
-            sprintf (newstr, "\\u%c%c%c%c",
+            snprintf (newstr, length + 1 - (newstr - result), "\\u%c%c%c%c",
                      hexdigit[(uc2 >> 12) & 0x0f], hexdigit[(uc2 >> 8) & 0x0f],
                      hexdigit[(uc2 >> 4) & 0x0f], hexdigit[uc2 & 0x0f]);
             newstr += 6;
diff -Paur --no-dereference -- gettext.upstream/libtextstyle/lib/term-style-control.c gettext/libtextstyle/lib/term-style-control.c
--- gettext.upstream/libtextstyle/lib/term-style-control.c
+++ gettext/libtextstyle/lib/term-style-control.c
@@ -369,9 +369,9 @@
         }
       else
         {
-          /* getpgrp () changes when the process gets put into the background
+          /* getpgid () changes when the process gets put into the background
              by a shell that implements job control.  */
-          if (p == getpgrp ())
+          if (p == getpgid (0))
             {
               pgrp_status = PGRP_IN_FOREGROUND;
               log_message ("pgrp_status = PGRP_IN_FOREGROUND\n");
