~ubuntu-branches/ubuntu/natty/centerim/natty

« back to all changes in this revision

Viewing changes to intl/printf.c

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2009-03-26 19:51:53 UTC
  • mfrom: (1.1.5 upstream) (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090326195153-dxo63t1lwbp2m592
Tags: 4.22.7-1ubuntu1
* Merge from debian unstable, Ubuntu remaining changes:
  - Packages that Depend/Recommend/Suggest firefox (metapackage) must
    must alternatively Depend/Recommend/Suggest abrowser.
* Bugfix-only release, fixed bugs: LP: #146308 and LP: #186381.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Formatted output to strings, using POSIX/XSI format strings with positions.
2
 
   Copyright (C) 2003, 2006 Free Software Foundation, Inc.
 
2
   Copyright (C) 2003 Free Software Foundation, Inc.
3
3
   Written by Bruno Haible <bruno@clisp.org>, 2003.
4
4
 
5
5
   This program is free software; you can redistribute it and/or modify it
47
47
 
48
48
#if !HAVE_POSIX_PRINTF
49
49
 
50
 
#include <errno.h>
51
 
#include <limits.h>
52
50
#include <stdlib.h>
53
51
#include <string.h>
54
52
 
55
 
/* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW.  */
56
 
#ifndef EOVERFLOW
57
 
# define EOVERFLOW E2BIG
58
 
#endif
59
 
 
60
53
/* When building a DLL, we must export some functions.  Note that because
61
54
   the functions are only defined for binary backward compatibility, we
62
55
   don't need to use __declspec(dllimport) in any case.  */
68
61
 
69
62
#define STATIC static
70
63
 
71
 
/* This needs to be consistent with libgnuintl.h.in.  */
72
 
#if defined __NetBSD__ || defined __CYGWIN__ || defined __MINGW32__
73
 
/* Don't break __attribute__((format(printf,M,N))).
74
 
   This redefinition is only possible because the libc in NetBSD, Cygwin,
75
 
   mingw does not have a function __printf__.  */
76
 
# define libintl_printf __printf__
77
 
#endif
78
 
 
79
64
/* Define auxiliary functions declared in "printf-args.h".  */
80
65
#include "printf-args.c"
81
66
 
103
88
      int retval = -1;
104
89
      if (result != NULL)
105
90
        {
106
 
          size_t written = fwrite (result, 1, length, stream);
 
91
          if (fwrite (result, 1, length, stream) == length)
 
92
            retval = length;
107
93
          free (result);
108
 
          if (written == length)
109
 
            {
110
 
              if (length > INT_MAX)
111
 
                errno = EOVERFLOW;
112
 
              else
113
 
                retval = length;
114
 
            }
115
94
        }
116
95
      return retval;
117
96
    }
165
144
          free (result);
166
145
          return -1;
167
146
        }
168
 
      if (length > INT_MAX)
169
 
        {
170
 
          errno = EOVERFLOW;
171
 
          return -1;
172
 
        }
173
147
      else
174
148
        return length;
175
149
    }
212
186
        {
213
187
          if (maxlength > 0)
214
188
            {
215
 
              size_t pruned_length =
216
 
                (length < maxlength ? length : maxlength - 1);
217
 
              memcpy (resultbuf, result, pruned_length);
218
 
              resultbuf[pruned_length] = '\0';
 
189
              if (length < maxlength)
 
190
                abort ();
 
191
              memcpy (resultbuf, result, maxlength - 1);
 
192
              resultbuf[maxlength - 1] = '\0';
219
193
            }
220
194
          free (result);
221
 
        }
222
 
      if (length > INT_MAX)
223
 
        {
224
 
          errno = EOVERFLOW;
225
195
          return -1;
226
196
        }
227
197
      else
254
224
  char *result = libintl_vasnprintf (NULL, &length, format, args);
255
225
  if (result == NULL)
256
226
    return -1;
257
 
  if (length > INT_MAX)
258
 
    {
259
 
      free (result);
260
 
      errno = EOVERFLOW;
261
 
      return -1;
262
 
    }
263
227
  *resultp = result;
264
228
  return length;
265
229
}
321
285
          for (i = 0; i < length; i++)
322
286
            if (fputwc (result[i], stream) == WEOF)
323
287
              break;
324
 
          free (result);
325
288
          if (i == length)
326
 
            {
327
 
              if (length > INT_MAX)
328
 
                errno = EOVERFLOW;
329
 
              else
330
 
                retval = length;
331
 
            }
 
289
            retval = length;
 
290
          free (result);
332
291
        }
333
292
      return retval;
334
293
    }
381
340
        {
382
341
          if (maxlength > 0)
383
342
            {
384
 
              size_t pruned_length =
385
 
                (length < maxlength ? length : maxlength - 1);
386
 
              memcpy (resultbuf, result, pruned_length * sizeof (wchar_t));
387
 
              resultbuf[pruned_length] = 0;
 
343
              if (length < maxlength)
 
344
                abort ();
 
345
              memcpy (resultbuf, result, (maxlength - 1) * sizeof (wchar_t));
 
346
              resultbuf[maxlength - 1] = 0;
388
347
            }
389
348
          free (result);
390
 
          /* Unlike vsnprintf, which has to return the number of character that
391
 
             would have been produced if the resultbuf had been sufficiently
392
 
             large, the vswprintf function has to return a negative value if
393
 
             the resultbuf was not sufficiently large.  */
394
 
          if (length >= maxlength)
395
 
            return -1;
396
 
        }
397
 
      if (length > INT_MAX)
398
 
        {
399
 
          errno = EOVERFLOW;
400
349
          return -1;
401
350
        }
402
351
      else