2 Copyright (C) 2003, 2005 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published
6 by the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 /* Written by Bruno Haible <bruno@clisp.org>. */
29 /* Handle multi-threaded applications. */
31 # include <bits/libc-lock.h>
36 /* Print an ASCII string with quotes and escape sequences where needed. */
38 print_escaped (FILE *stream
, const char *str
)
41 for (; *str
!= '\0'; str
++)
44 fputs ("\\n\"", stream
);
47 fputs ("\n\"", stream
);
51 if (*str
== '"' || *str
== '\\')
58 static char *last_logfilename
= NULL
;
59 static FILE *last_logfile
= NULL
;
60 __libc_lock_define_initialized (static, lock
)
63 _nl_log_untranslated_locked (const char *logfilename
, const char *domainname
,
64 const char *msgid1
, const char *msgid2
, int plural
)
68 /* Can we reuse the last opened logfile? */
69 if (last_logfilename
== NULL
|| strcmp (logfilename
, last_logfilename
) != 0)
71 /* Close the last used logfile. */
72 if (last_logfilename
!= NULL
)
74 if (last_logfile
!= NULL
)
76 fclose (last_logfile
);
79 free (last_logfilename
);
80 last_logfilename
= NULL
;
82 /* Open the logfile. */
83 last_logfilename
= (char *) malloc (strlen (logfilename
) + 1);
84 if (last_logfilename
== NULL
)
86 strcpy (last_logfilename
, logfilename
);
87 last_logfile
= fopen (logfilename
, "a");
88 if (last_logfile
== NULL
)
91 logfile
= last_logfile
;
93 fprintf (logfile
, "domain ");
94 print_escaped (logfile
, domainname
);
95 fprintf (logfile
, "\nmsgid ");
96 print_escaped (logfile
, msgid1
);
99 fprintf (logfile
, "\nmsgid_plural ");
100 print_escaped (logfile
, msgid2
);
101 fprintf (logfile
, "\nmsgstr[0] \"\"\n");
104 fprintf (logfile
, "\nmsgstr \"\"\n");
105 putc ('\n', logfile
);
108 /* Add to the log file an entry denoting a failed translation. */
110 _nl_log_untranslated (const char *logfilename
, const char *domainname
,
111 const char *msgid1
, const char *msgid2
, int plural
)
113 __libc_lock_lock (lock
);
114 _nl_log_untranslated_locked (logfilename
, domainname
, msgid1
, msgid2
, plural
);
115 __libc_lock_unlock (lock
);