~eday/gearmand/fixes

« back to all changes in this revision

Viewing changes to libgearman/error.c

  • Committer: Eric Day
  • Date: 2009-09-26 16:54:44 UTC
  • Revision ID: eday@oddments.org-20090926165444-g2rbeci54p14gjsh
Removed list add/del macros from libgearman. Moved error_set to gearman.c since first arg is a gearman struct (following OO guidelines).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Gearman server and library
2
 
 * Copyright (C) 2008 Brian Aker, Eric Day
3
 
 * All rights reserved.
4
 
 *
5
 
 * Use and distribution licensed under the BSD license.  See
6
 
 * the COPYING file in the parent directory for full text.
7
 
 */
8
 
 
9
 
/**
10
 
 * @file
11
 
 * @brief Error definitions
12
 
 */
13
 
 
14
 
#include "common.h"
15
 
 
16
 
/*
17
 
 * Private definitions
18
 
 */
19
 
 
20
 
void gearman_error_set(gearman_st *gearman, const char *function,
21
 
                       const char *format, ...)
22
 
{
23
 
  size_t length;
24
 
  char *ptr;
25
 
  char log_buffer[GEARMAN_MAX_ERROR_SIZE];
26
 
  va_list arg;
27
 
 
28
 
  va_start(arg, format);
29
 
 
30
 
  length= strlen(function);
31
 
 
32
 
  /* Copy the function name and : before the format */
33
 
  ptr= memcpy(log_buffer, function, length);
34
 
  ptr+= length;
35
 
  ptr[0]= ':';
36
 
  ptr++;
37
 
 
38
 
  length= (size_t)vsnprintf(ptr, GEARMAN_MAX_ERROR_SIZE - length - 1, format,
39
 
                            arg);
40
 
 
41
 
  if (gearman->log_fn == NULL)
42
 
    memcpy(gearman->last_error, log_buffer, length);
43
 
  else
44
 
  {
45
 
    (*(gearman->log_fn))(log_buffer, GEARMAN_VERBOSE_FATAL,
46
 
                         (void *)(gearman)->log_context);
47
 
  }
48
 
 
49
 
  va_end(arg);
50
 
}