~ubuntu-branches/ubuntu/hardy/ntfs-3g/hardy

« back to all changes in this revision

Viewing changes to libntfs-3g/logging.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Cécile (Le_Vert)
  • Date: 2006-11-24 00:33:43 UTC
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20061124003343-9ag45l8hiuz69nkd
Tags: upstream-0.0.0+20061031
Import upstream version 0.0.0+20061031

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 * logging.c - Centralised logging.  Part of the Linux-NTFS project.
 
2
 * logging.c - Centralised logging.  Originated from the Linux-NTFS project.
3
3
 *
4
4
 * Copyright (c) 2005 Richard Russon
5
5
 * Copyright (c) 2005-2006 Szabolcs Szakacsits
15
15
 * GNU General Public License for more details.
16
16
 *
17
17
 * You should have received a copy of the GNU General Public License
18
 
 * along with this program (in the main directory of the Linux-NTFS
 
18
 * along with this program (in the main directory of the NTFS-3G
19
19
 * distribution in the file COPYING); if not, write to the Free Software
20
20
 * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
21
 */
80
80
#endif
81
81
        NTFS_LOG_LEVEL_INFO | NTFS_LOG_LEVEL_QUIET | NTFS_LOG_LEVEL_WARNING |
82
82
        NTFS_LOG_LEVEL_ERROR | NTFS_LOG_LEVEL_PERROR | NTFS_LOG_LEVEL_CRITICAL |
83
 
        NTFS_LOG_LEVEL_REASON | NTFS_LOG_LEVEL_PROGRESS,
 
83
        NTFS_LOG_LEVEL_PROGRESS,
84
84
        NTFS_LOG_FLAG_ONLYNAME,
85
85
#ifdef DEBUG
86
86
        ntfs_log_handler_outerr
349
349
        const char *file, __attribute__((unused)) int line, u32 level,
350
350
        void *data __attribute__((unused)), const char *format, va_list args)
351
351
{
352
 
        const int reason_size = 128;
353
 
        static char *reason = NULL;
354
352
        int ret = 0;
355
353
        int olderr = errno;
356
354
 
357
 
        if (level == NTFS_LOG_LEVEL_REASON) {
358
 
                if (!reason)
359
 
                        reason = ntfs_malloc(reason_size);
360
 
                if (reason) {
361
 
                        memset(reason, 0, reason_size);
362
 
                        return vsnprintf(reason, reason_size, format, args);
363
 
                } else {
364
 
                        /* Rather than call ourselves, just drop through */
365
 
                        level = NTFS_LOG_LEVEL_PERROR;
366
 
                        format = "Couldn't create reason";
367
 
                        args = NULL;
368
 
                        olderr = errno;
369
 
                }
370
 
        }
371
 
 
372
355
        if ((ntfs_log.flags & NTFS_LOG_FLAG_ONLYNAME) &&
373
356
            (strchr(file, PATH_SEP)))           /* Abbreviate the filename */
374
357
                file = strrchr(file, PATH_SEP) + 1;
427
410
int ntfs_log_handler_fprintf(const char *function, const char *file,
428
411
        int line, u32 level, void *data, const char *format, va_list args)
429
412
{
430
 
        const int reason_size = 128;
431
 
        static char *reason = NULL;
432
413
        int ret = 0;
433
414
        int olderr = errno;
434
415
        FILE *stream;
439
420
                return 0;       /* If it's NULL, we can't do anything. */
440
421
        stream = (FILE*)data;
441
422
 
442
 
        if (level == NTFS_LOG_LEVEL_REASON) {
443
 
                if (!reason)
444
 
                        reason = ntfs_malloc(reason_size);
445
 
                if (reason) {
446
 
                        memset(reason, 0, reason_size);
447
 
                        return vsnprintf(reason, reason_size, format, args);
448
 
                } else {
449
 
                        /* Rather than call ourselves, just drop through */
450
 
                        level = NTFS_LOG_LEVEL_PERROR;
451
 
                        format = "Couldn't create reason";
452
 
                        args = NULL;
453
 
                        olderr = errno;
454
 
                }
455
 
        }
456
 
 
457
423
        if (ntfs_log.flags & NTFS_LOG_FLAG_COLOUR) {
458
424
                /* Pick a colour determined by the log level */
459
425
                switch (level) {
503
469
 
504
470
        ret += vfprintf(stream, format, args);
505
471
 
506
 
        if (level & NTFS_LOG_LEVEL_PERROR) {
507
 
                if (reason)
508
 
                        ret += fprintf(stream, ": %s\n", reason);
509
 
                else
510
 
                        ret += fprintf(stream, ": %s\n", strerror(olderr));
511
 
        }
 
472
        if (level & NTFS_LOG_LEVEL_PERROR)
 
473
                ret += fprintf(stream, ": %s\n", strerror(olderr));
512
474
 
513
475
        if (col_suffix)
514
476
                ret += fprintf(stream, col_suffix);