示例#1
0
static int notify(processor_t::idp_notify msgid, ...)
{
  va_list va;
  va_start(va, msgid);

// A well behaving processor module should call invoke_callbacks()
// in his notify() function. If this function returns 0, then
// the processor module should process the notification itself
// Otherwise the code should be returned to the caller:

  int code = invoke_callbacks(HT_IDP, msgid, va);
  if ( code ) return code;

  switch ( msgid )
  {
    case processor_t::init:
      helper.create("$ st20");
      helper.supval(0, device, sizeof(device));
      break;

    case processor_t::term:
      free_ioports(ports, numports);
    default:
      break;

    case processor_t::newfile:  // new file loaded
    case processor_t::oldfile:  // old file loaded
      load_symbols();
      break;

    case processor_t::savebase:
    case processor_t::closebase:
      helper.supset(0, device);
      break;

    case processor_t::newprc:   // new processor type
      procnum = va_arg(va, int);
      if ( isc4() ) ph.retcodes = retcodes4;
      break;

    case processor_t::is_jump_func:
      {
        const func_t *pfn = va_arg(va, const func_t *);
        ea_t *jump_target = va_arg(va, ea_t *);
        return is_jump_func(pfn, jump_target);
      }

    case processor_t::is_sane_insn:
      return is_sane_insn(va_arg(va, int));

    case processor_t::may_be_func:
                                // can a function start here?
                                // arg: none, the instruction is in 'cmd'
                                // returns: probability 0..100
                                // 'cmd' structure is filled upon the entrace
                                // the idp module is allowed to modify 'cmd'
      return may_be_func();

  }
  va_end(va);
  return 1;
}
示例#2
0
文件: log.c 项目: jianglei12138/avahi
void avahi_log_notice(const char*format, ...) {
    va_list ap;
    va_start(ap, format);
    avahi_log_ap(AVAHI_LOG_NOTICE, format, ap);
    va_end(ap);
}
示例#3
0
文件: log.c 项目: jianglei12138/avahi
void avahi_log_debug(const char*format, ...) {
    va_list ap;
    va_start(ap, format);
    avahi_log_ap(AVAHI_LOG_DEBUG, format, ap);
    va_end(ap);
}
示例#4
0
void	reallyAbort(const char *fmt, ...) {

	// Format the error message into our buffer

	va_list ap;
	va_start(ap, fmt);
	//SECURITY-UPDATE:2/3/07
	//vsprintf(g_errMsg, fmt, ap);
	vsprintf_s(g_errMsg,sizeof(g_errMsg), fmt, ap);
	va_end(ap);

	// Tack on the source file and line number

	//SECURITY-UPDATE:2/3/07
	//sprintf(strchr(g_errMsg, '\0'), "\n%s line %d", abortSourceFile, abortSourceLine);
	sprintf_s(strchr(g_errMsg, '\0'),sizeof(g_errMsg)-strlen(g_errMsg), "\n%s line %d", abortSourceFile, abortSourceLine);

	// Shutdown renderer so we can see the error message

	gRenderer->Release();

	// Windows?  Dump message box

	#ifdef WIN32

		// Check if we're under the debugger

		if (areWeBeingDebugged()) {

			// Dump error message to the debug console

			OutputDebugString(TEXT("FATAL ERROR: "));
			OutputDebugString(g_errMsg);
			OutputDebugString(TEXT("\n"));

			// Break the program, so we can check out what was going on.

			/*_asm {

				// HELLO! If you hit this breakpoint, then look at the debug
				// console, and go up the call stack to see what went wrong!

				int 3;
			}*/
			assert(0);

			// You can try to keep running, if you want...

		} else {

			// Just dump a message box and terminate the app
			g_errorExit=true; // flag that there's been an error
			//DestroyWindow(gWindowsWrapper.getHandle()); // post quit message so we can show dialog box last
			DestroyWindow(gRenderer->GetWindowHandle());
			ExitProcess(1); // so we don't proceed with whatever caused this abort
		}
	#else

		// Just dump it to printf and use exit.  On most OSs,
		// this is basically useless for debugging, so you'd
		// want to do better, especially under the debugger

		printf("FATAL ERROR: %s\n", errMsg);
		exit(1);

	#endif

#endif
}
示例#5
0
文件: log.c 项目: jianglei12138/avahi
void avahi_log_error(const char*format, ...) {
    va_list ap;
    va_start(ap, format);
    avahi_log_ap(AVAHI_LOG_ERROR, format, ap);
    va_end(ap);
}
示例#6
0
文件: log.cpp 项目: crazyhg/pi
void CLog::Log(int loglevel, const char *format, ... )
{
  pthread_mutex_lock(&m_log_mutex);

  static const char* prefixFormat = "%02.2d:%02.2d:%02.2d T:%" PRIu64 " %7s: ";
/*#if !(defined(_DEBUG) || defined(PROFILE))
  if (m_logLevel > LOG_LEVEL_NORMAL ||
     (m_logLevel > LOG_LEVEL_NONE && loglevel >= LOGNOTICE))
#endif*/
  {
    if (!m_file)
    {
      pthread_mutex_unlock(&m_log_mutex);
      return;
    }

    SYSTEMTIME time;
    //GetLocalTime(&time);

    CStdString strPrefix, strData;

    strData.reserve(16384);
    va_list va;
    va_start(va, format);
    strData.FormatV(format,va);
    va_end(va);

    if (m_repeatLogLevel == loglevel && m_repeatLine == strData)
    {
      m_repeatCount++;
      pthread_mutex_unlock(&m_log_mutex);
      return;
    }
    else if (m_repeatCount)
    {
      CStdString strData2;
      time.wHour = 0;
      time.wMinute = 0;
      time.wSecond = 0;
      strPrefix.Format(prefixFormat, time.wHour, time.wMinute, time.wSecond, (uint64_t)0, levelNames[m_repeatLogLevel]);

      strData2.Format("Previous line repeats %d times." LINE_ENDING, m_repeatCount);
      fputs(strPrefix.c_str(), m_file);
      fputs(strData2.c_str(), m_file);
      OutputDebugString(strData2);
      m_repeatCount = 0;
    }
    
    m_repeatLine      = strData;
    m_repeatLogLevel  = loglevel;

    unsigned int length = 0;
    while ( length != strData.length() )
    {
      length = strData.length();
      strData.TrimRight(" ");
      strData.TrimRight('\n');
      strData.TrimRight("\r");
    }

    if (!length)
    {
      pthread_mutex_unlock(&m_log_mutex);
      return;
    }
    
    OutputDebugString(strData);

    /* fixup newline alignment, number of spaces should equal prefix length */
    strData.Replace("\n", LINE_ENDING"                                            ");
    strData += LINE_ENDING;

    strPrefix.Format(prefixFormat, time.wHour, time.wMinute, time.wSecond, (uint64_t)0, levelNames[loglevel]);

    fputs(strPrefix.c_str(), m_file);
    fputs(strData.c_str(), m_file);
    //fputs(strPrefix.c_str(), stdout);
    //fputs(strData.c_str(), stdout);
    fflush(m_file);
  }

  pthread_mutex_unlock(&m_log_mutex);
}
示例#7
0
void _sid_dbgprintf(const char* format, ...) {
        va_list args;
        va_start(args, format);
        vprintf(format, args);
        va_end(args);
}
示例#8
0
void Log::outCommand(uint32 account, const char* str, ...)
{
    if (!str)
        return;

    if (m_logLevel >= LOG_LVL_DETAIL)
    {
        if (m_colored)
            SetColor(true, m_colors[LogDetails]);

        if (m_includeTime)
            outTime();

        va_list ap;
        va_start(ap, str);
        vutf8printf(stdout, str, &ap);
        va_end(ap);

        if (m_colored)
            ResetColor(true);

        printf("\n");
    }

    if (logfile && m_logFileLevel >= LOG_LVL_DETAIL)
    {
        va_list ap;
        outTimestamp(logfile);
        va_start(ap, str);
        vfprintf(logfile, str, ap);
        fprintf(logfile, "\n");
        va_end(ap);
        fflush(logfile);
    }

    if (m_gmlog_per_account)
    {
        if (FILE* per_file = openGmlogPerAccount(account))
        {
            va_list ap;
            outTimestamp(per_file);
            va_start(ap, str);
            vfprintf(per_file, str, ap);
            fprintf(per_file, "\n");
            va_end(ap);
            fclose(per_file);
        }
    }
    else if (gmLogfile)
    {
        va_list ap;
        outTimestamp(gmLogfile);
        va_start(ap, str);
        vfprintf(gmLogfile, str, ap);
        fprintf(gmLogfile, "\n");
        va_end(ap);
        fflush(gmLogfile);
    }

    fflush(stdout);
}
示例#9
0
文件: nsock_write.c 项目: 6e6f36/nmap
/* Same as nsock_write except you can use a printf-style format and you can only use this for ASCII strings */
nsock_event_id nsock_printf(nsock_pool ms_pool, nsock_iod ms_iod,
          nsock_ev_handler handler, int timeout_msecs, void *userdata, char *format, ...) {
  mspool *nsp = (mspool *)ms_pool;
  msiod *nsi = (msiod *)ms_iod;
  msevent *nse;
  char buf[4096];
  char *buf2 = NULL;
  int res, res2;
  int strlength = 0;
  char displaystr[256];

  va_list ap;
  va_start(ap,format);

  nse = msevent_new(nsp, NSE_TYPE_WRITE, nsi, timeout_msecs, handler, userdata);
  assert(nse);

  res = Vsnprintf(buf, sizeof(buf), format, ap);
  va_end(ap);

  if (res != -1) {
    if (res > sizeof(buf)) {
      buf2 = (char * )safe_malloc(res + 16);
      res2 = Vsnprintf(buf2, sizeof(buf), format, ap);
      if (res2 == -1 || res2 > res) {
        free(buf2);
        buf2 = NULL;
      } else
        strlength = res2;
    } else {
      buf2 = buf;
      strlength = res;
    }
  }

  if (!buf2) {
    nse->event_done = 1;
    nse->status = NSE_STATUS_ERROR;
    nse->errnum = EMSGSIZE;
  } else {
    if (strlength == 0) {
      nse->event_done = 1;
      nse->status = NSE_STATUS_SUCCESS;
    } else {
      fs_cat(&nse->iobuf, buf2, strlength);
    }
  }

  if (nsp->loglevel == NSOCK_LOG_DBG_ALL && nse->status != NSE_STATUS_ERROR && strlength < 80) {
    memcpy(displaystr, ": ", 2);
    memcpy(displaystr + 2, buf2, strlength);
    displaystr[2 + strlength] = '\0';
    replacenonprintable(displaystr + 2, strlength, '.');
  } else {
    displaystr[0] = '\0';
  }
  if (nsi->peerlen > 0)
    nsock_log_debug(nsp, "Write request for %d bytes to IOD #%li EID %li [%s]%s",
                    strlength, nsi->id, nse->id, get_peeraddr_string(nsi), displaystr);
  else
    nsock_log_debug(nsp, "Write request for %d bytes to IOD #%li EID %li (peer unspecified)%s",
                    strlength, nsi->id, nse->id, displaystr);

  if (buf2 != buf)
    free(buf2);

  nsp_add_event(nsp, nse);

  return nse->id;
}
示例#10
0
CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...)
{
  va_list arg;
  long *param_longp=NULL;
  double *param_doublep=NULL;
  char **param_charp=NULL;
  struct curl_slist **param_slistp=NULL;
#ifdef MSG_PEEK
  char buf;
#endif
  int type;

  if(!data)
    return CURLE_BAD_FUNCTION_ARGUMENT;

  va_start(arg, info);

  type = CURLINFO_TYPEMASK & (int)info;
  switch(type) {
  case CURLINFO_STRING:
    param_charp = va_arg(arg, char **);
    if(NULL == param_charp)
      return CURLE_BAD_FUNCTION_ARGUMENT;
    break;
  case CURLINFO_LONG:
    param_longp = va_arg(arg, long *);
    if(NULL == param_longp)
      return CURLE_BAD_FUNCTION_ARGUMENT;
    break;
  case CURLINFO_DOUBLE:
    param_doublep = va_arg(arg, double *);
    if(NULL == param_doublep)
      return CURLE_BAD_FUNCTION_ARGUMENT;
    break;
  case CURLINFO_SLIST:
    param_slistp = va_arg(arg, struct curl_slist **);
    if(NULL == param_slistp)
      return CURLE_BAD_FUNCTION_ARGUMENT;
    break;
  default:
    return CURLE_BAD_FUNCTION_ARGUMENT;
  }

  switch(info) {
  case CURLINFO_EFFECTIVE_URL:
    *param_charp = data->change.url?data->change.url:(char *)"";
    break;
  case CURLINFO_RESPONSE_CODE:
    *param_longp = data->info.httpcode;
    break;
  case CURLINFO_HTTP_CONNECTCODE:
    *param_longp = data->info.httpproxycode;
    break;
  case CURLINFO_FILETIME:
    *param_longp = data->info.filetime;
    break;
  case CURLINFO_HEADER_SIZE:
    *param_longp = data->info.header_size;
    break;
  case CURLINFO_REQUEST_SIZE:
    *param_longp = data->info.request_size;
    break;
  case CURLINFO_TOTAL_TIME:
    *param_doublep = data->progress.timespent;
    break;
  case CURLINFO_NAMELOOKUP_TIME:
    *param_doublep = data->progress.t_nslookup;
    break;
  case CURLINFO_CONNECT_TIME:
    *param_doublep = data->progress.t_connect;
    break;
  case CURLINFO_PRETRANSFER_TIME:
    *param_doublep =  data->progress.t_pretransfer;
    break;
  case CURLINFO_STARTTRANSFER_TIME:
    *param_doublep = data->progress.t_starttransfer;
    break;
  case CURLINFO_SIZE_UPLOAD:
    *param_doublep =  (double)data->progress.uploaded;
    break;
  case CURLINFO_SIZE_DOWNLOAD:
    *param_doublep = (double)data->progress.downloaded;
    break;
  case CURLINFO_SPEED_DOWNLOAD:
    *param_doublep =  (double)data->progress.dlspeed;
    break;
  case CURLINFO_SPEED_UPLOAD:
    *param_doublep = (double)data->progress.ulspeed;
    break;
  case CURLINFO_SSL_VERIFYRESULT:
    *param_longp = data->set.ssl.certverifyresult;
    break;
  case CURLINFO_CONTENT_LENGTH_DOWNLOAD:
    *param_doublep = (double)data->progress.size_dl;
    break;
  case CURLINFO_CONTENT_LENGTH_UPLOAD:
    *param_doublep = (double)data->progress.size_ul;
    break;
  case CURLINFO_REDIRECT_TIME:
    *param_doublep =  data->progress.t_redirect;
    break;
  case CURLINFO_REDIRECT_COUNT:
    *param_longp = data->set.followlocation;
    break;
  case CURLINFO_CONTENT_TYPE:
    *param_charp = data->info.contenttype;
    break;
  case CURLINFO_PRIVATE:
    *param_charp = data->set.private_data;
    break;
  case CURLINFO_HTTPAUTH_AVAIL:
    *param_longp = data->info.httpauthavail;
    break;
  case CURLINFO_PROXYAUTH_AVAIL:
    *param_longp = data->info.proxyauthavail;
    break;
  case CURLINFO_OS_ERRNO:
    *param_longp = data->state.os_errno;
    break;
  case CURLINFO_NUM_CONNECTS:
    *param_longp = data->info.numconnects;
    break;
  case CURLINFO_SSL_ENGINES:
    *param_slistp = Curl_ssl_engines_list(data);
    break;
  case CURLINFO_COOKIELIST:
    *param_slistp = Curl_cookie_list(data);
    break;
  case CURLINFO_FTP_ENTRY_PATH:
    /* Return the entrypath string from the most recent connection.
       This pointer was copied from the connectdata structure by FTP.
       The actual string may be free()ed by subsequent libcurl calls so
       it must be copied to a safer area before the next libcurl call.
       Callers must never free it themselves. */
    *param_charp = data->state.most_recent_ftp_entrypath;
    break;
  case CURLINFO_LASTSOCKET:
    if((data->state.lastconnect != -1) &&
       (data->state.connc->connects[data->state.lastconnect] != NULL)) {
      struct connectdata *c = data->state.connc->connects
        [data->state.lastconnect];
      *param_longp = c->sock[FIRSTSOCKET];
      /* we have a socket connected, let's determine if the server shut down */
      /* determine if ssl */
      if(c->ssl[FIRSTSOCKET].use) {
        /* use the SSL context */
        if (!Curl_ssl_check_cxn(c))
          *param_longp = -1;   /* FIN received */
      }
/* Minix 3.1 doesn't support any flags on recv; just assume socket is OK */
#ifdef MSG_PEEK
      else {
        /* use the socket */
        if(recv((RECV_TYPE_ARG1)c->sock[FIRSTSOCKET], (RECV_TYPE_ARG2)&buf,
                (RECV_TYPE_ARG3)1, (RECV_TYPE_ARG4)MSG_PEEK) == 0) {
          *param_longp = -1;   /* FIN received */
        }
      }
#endif
    }
    else
      *param_longp = -1;
    break;
  default:
    return CURLE_BAD_FUNCTION_ARGUMENT;
  }
  return CURLE_OK;
}
示例#11
0
void
gvfs_udisks2_utils_spawn (guint                timeout_seconds,
                          GCancellable        *cancellable,
                          GAsyncReadyCallback  callback,
                          gpointer             user_data,
                          const gchar         *command_line_format,
                          ...)
{
  va_list var_args;
  SpawnData *data;
  GError *error;
  gint child_argc;
  gchar **child_argv = NULL;

  data = g_slice_new0 (SpawnData);
  data->simple = g_simple_async_result_new (NULL,
                                            callback,
                                            user_data,
                                            gvfs_udisks2_utils_spawn);
  data->main_context = g_main_context_get_thread_default ();
  if (data->main_context != NULL)
    g_main_context_ref (data->main_context);

  data->cancellable = cancellable != NULL ? g_object_ref (cancellable) : NULL;

  va_start (var_args, command_line_format);
  data->command_line = g_strdup_vprintf (command_line_format, var_args);
  va_end (var_args);

  data->child_stdout = g_string_new (NULL);
  data->child_stderr = g_string_new (NULL);
  data->child_stdout_fd = -1;
  data->child_stderr_fd = -1;

  /* the life-cycle of SpawnData is tied to its GSimpleAsyncResult */
  g_simple_async_result_set_op_res_gpointer (data->simple, data, (GDestroyNotify) spawn_data_free);

  error = NULL;
  if (data->cancellable != NULL)
    {
      /* could already be cancelled */
      error = NULL;
      if (g_cancellable_set_error_if_cancelled (data->cancellable, &error))
        {
          g_simple_async_result_take_error (data->simple, error);
          g_simple_async_result_complete_in_idle (data->simple);
          g_object_unref (data->simple);
          goto out;
        }

      data->cancellable_handler_id = g_cancellable_connect (data->cancellable,
                                                            G_CALLBACK (on_cancelled),
                                                            data,
                                                            NULL);
    }

  error = NULL;
  if (!g_shell_parse_argv (data->command_line,
                           &child_argc,
                           &child_argv,
                           &error))
    {
      g_prefix_error (&error,
                      "Error parsing command-line `%s': ",
                      data->command_line);
      g_simple_async_result_take_error (data->simple, error);
      g_simple_async_result_complete_in_idle (data->simple);
      g_object_unref (data->simple);
      goto out;
    }

  error = NULL;
  if (!g_spawn_async_with_pipes (NULL, /* working directory */
                                 child_argv,
                                 NULL, /* envp */
                                 G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
                                 NULL, /* child_setup */
                                 NULL, /* child_setup's user_data */
                                 &(data->child_pid),
                                 NULL, /* gint *stdin_fd */
                                 &(data->child_stdout_fd),
                                 &(data->child_stderr_fd),
                                 &error))
    {
      g_prefix_error (&error,
                      "Error spawning command-line `%s': ",
                      data->command_line);
      g_simple_async_result_take_error (data->simple, error);
      g_simple_async_result_complete_in_idle (data->simple);
      g_object_unref (data->simple);
      goto out;
    }

  if (timeout_seconds > 0)
    {
      data->timeout_source = g_timeout_source_new_seconds (timeout_seconds);
      g_source_set_priority (data->timeout_source, G_PRIORITY_DEFAULT);
      g_source_set_callback (data->timeout_source, timeout_cb, data, NULL);
      g_source_attach (data->timeout_source, data->main_context);
      g_source_unref (data->timeout_source);
    }

  data->child_watch_source = g_child_watch_source_new (data->child_pid);
  g_source_set_callback (data->child_watch_source, (GSourceFunc) child_watch_cb, data, NULL);
  g_source_attach (data->child_watch_source, data->main_context);
  g_source_unref (data->child_watch_source);

  data->child_stdout_channel = g_io_channel_unix_new (data->child_stdout_fd);
  g_io_channel_set_flags (data->child_stdout_channel, G_IO_FLAG_NONBLOCK, NULL);
  data->child_stdout_source = g_io_create_watch (data->child_stdout_channel, G_IO_IN);
  g_source_set_callback (data->child_stdout_source, (GSourceFunc) read_child_stdout, data, NULL);
  g_source_attach (data->child_stdout_source, data->main_context);
  g_source_unref (data->child_stdout_source);

  data->child_stderr_channel = g_io_channel_unix_new (data->child_stderr_fd);
  g_io_channel_set_flags (data->child_stderr_channel, G_IO_FLAG_NONBLOCK, NULL);
  data->child_stderr_source = g_io_create_watch (data->child_stderr_channel, G_IO_IN);
  g_source_set_callback (data->child_stderr_source, (GSourceFunc) read_child_stderr, data, NULL);
  g_source_attach (data->child_stderr_source, data->main_context);
  g_source_unref (data->child_stderr_source);

 out:
  g_strfreev (child_argv);
}
示例#12
0
文件: glue.c 项目: aosm/dyld
void _ZN4dyld4warnEPKcz(const char* format, ...) {
	va_list	list;
	va_start(list, format);
	gSyscallHelpers->vwarn(format, list);
	va_end(list);
}
示例#13
0
void DebugPrint( LPCTSTR message, ... )
{
	va_list args;
	va_start( args, message );
	DebugPrintV( message, args );
}
示例#14
0
void Script::callFunction(const char *func,const char *sig,...)
{
    va_list vl;
    int narg,nres;

    va_start(vl,sig);
    lua_getglobal(mThreadState,func);

    if(lua_isfunction(mThreadState,-1))
    {
        narg = 0;

        while(*sig)
        {
            switch (*sig++)
            {

            case 'd':
                lua_pushnumber(mThreadState,va_arg(vl,double));
                break;
            case 'i':
                lua_pushnumber(mThreadState,va_arg(vl,int));
                break;
            case 's':
                lua_pushstring(mThreadState,va_arg(vl,char *));
                break;

            case '>':
                goto endwhile;
                break;

            default:
                break;
            }

            narg++;

            luaL_checkstack(mThreadState,1,"too many arguments");
        }

endwhile:

        nres = strlen(sig);

        if(lua_pcall(mThreadState,narg,nres,0) != 0)
        {
            _formatError();
        }

        nres = -nres;

        while(*sig)
        {
            switch (*sig++)
            {
            case 'd':
            {
                if(!lua_isnumber(mThreadState,nres))
                {
                    _formatError();
                }

                *va_arg(vl,double *) = lua_tonumber(mThreadState,nres);
            }
            break;

            case 'i':
            {
                if(!lua_isnumber(mThreadState,nres))
                {
                    _formatError();
                }

                *va_arg(vl,int*) = (int)lua_tonumber(mThreadState,nres);
            }
            break;

            case 's':
            {
                if(!lua_isstring(mThreadState,nres))
                {
                    _formatError();
                }

                *va_arg(vl,const char **) = lua_tostring(mThreadState,nres);
            }
            break;

            default:
            {
                _formatError();
            }
            break;
            }

            nres++;
        }
    }

    va_end(vl);
}
示例#15
0
void SDL_SetError (const char *fmt, ...)
{
	va_list ap;
	SDL_error *error;

	/* Copy in the key, mark error as valid */
	error = SDL_GetErrBuf();
	error->error = 1;
	strncpy((char *)error->key, fmt, sizeof(error->key));
	error->key[sizeof(error->key)-1] = '\0';

	va_start(ap, fmt);
	error->argc = 0;
	while ( *fmt ) {
		if ( *fmt++ == '%' ) {
			switch (*fmt++) {
			    case 0:  /* Malformed format string.. */
				--fmt;
				break;
#if 0	/* What is a character anyway?  (UNICODE issues) */
			    case 'c':
				error->args[error->argc++].value_c =
						va_arg(ap, unsigned char);
				break;
#endif
			    case 'd':
				error->args[error->argc++].value_i =
							va_arg(ap, int);
				break;
			    case 'f':
				error->args[error->argc++].value_f =
							va_arg(ap, double);
				break;
			    case 'p':
				error->args[error->argc++].value_ptr =
							va_arg(ap, void *);
				break;
			    case 's':
				{
				  int index = error->argc;
				  strncpy((char *)error->args[index].buf,
					va_arg(ap, char *), ERR_MAX_STRLEN);
				  error->args[index].buf[ERR_MAX_STRLEN-1] = 0;
				  error->argc++;
				}
				break;
			    default:
				break;
			}
			if ( error->argc >= ERR_MAX_ARGS ) {
				break;
			}
		}
	}
	va_end(ap);

#ifndef DISABLE_STDIO
	/* If we are in debug mode, print out an error message */
#ifdef DEBUG_ERROR
	fprintf(stderr, "SDL_SetError: %s\n", SDL_GetError());
#else
	if ( getenv("SDL_DEBUG") ) {
		fprintf(stderr, "SDL_SetError: %s\n", SDL_GetError());
	}
#endif
#endif /* !DISABLE_STDIO */
}
示例#16
0
文件: bfmt.c 项目: duper/blackbag
int
bscanf(u_char *buf, size_t len, const char *fmt, ...) {
	va_list ap;
	size_t size_reg = 0;
	u_char *cp = buf;
	u_char *ep = &buf[len];
	int ret = 0;

	enum {
		BS_SWAP = 0x1,
		BS_SAVE = 0x2,
		BS_SKIP = 0x5
	};	

	va_start(ap, fmt);

	while(*fmt && cp < ep) {
		if(*fmt == '%') {
			void *spp = NULL;
			unsigned flags = 0;
			unsigned char c;
			size_t n = 0;
			size_t size = 0;
			size_t max_size = ~0;	
			size_t (*fn)(u_int32_t val) = NULL;

			for(c = *++fmt; c && strchr("x&__", c); c = *++fmt) {
				switch(c) {
				case 'x':
					flags |= BS_SWAP;
					break;
				case '&':
					flags |= BS_SAVE;
					break;
				case '_':
					flags |= BS_SKIP;
					break;
				case '+':
					fn = va_arg(ap, void*);
					break;
				}
			}

			for(n = 0; isdigit(*fmt); fmt++) {
				int d = *fmt - '0';
				n = 10 * n + d;		
			}

			if(n) size_reg = n;

			if(*fmt == '#') {
				fmt += 1;
				for(n = 0; isdigit(*fmt); fmt++) {
					int d = *fmt - '0';
					n = 10 * n + d;
				}
	
				if(n) max_size = n;
			}

			switch(tolower(*fmt)) { 
			case 'b': 
			case '.': size = 1; break;       
			case 'h': size = 2; break;
			case 'l': size = 4; break;
			case 'q': size = 8; break;
			case 'p':
			case 'o':
			case 's': size = size_reg; break;
			default:
				assert(!"valid size code");
				break;			       		
			}

			if((cp + size) > ep) 
				break;

			if(flags & BS_SKIP || *fmt == '.') 
				cp += size;
			else {
#define SAVE(t) {					\
	t v = va_arg(ap, t);				\
	spp = v;					\
	memcpy((u_char *)v, cp, size);			\
  	switch(size) {					\
	case 2: *v = ntohs(*v);	break;			\
 	case 4: *v = ntohl(*v);	break;			\
	case 8: *v = ntohll(*v); break;	 		\
	default: break;					\
       	}						\
	if(flags & BS_SWAP) {				\
		switch(size) { 				\
		case 2: *v = swp16(*v); break;		\
		case 4: *v = swp32(*v);	break;		\
		case 8: *v = swp64(*v);	break;		\
		default:				\
			break;				\
		}					\
	}	   					\
	if(flags & BS_SAVE) {				\
		if(fn) size_reg = fn(*v);		\
		else size_reg = *v;			\
	}						\
	cp += size;					\
} break
				switch(*fmt) {
				case 'b': SAVE(char*);
				case 'B': SAVE(u_char*);
				case 'h': SAVE(int16_t*);
				case 'H': SAVE(u_int16_t*);
				case 'l': SAVE(int32_t*);
				case 'L': SAVE(u_int32_t*);
				case 'q': SAVE(int64_t*);
       				case 'Q': SAVE(u_int64_t*);
				case 'O': {
					u_char **sp = va_arg(ap,u_char **);
					*sp = cp;
					cp += size;
					break;
				}
       				case 'P': {
					u_char **sp = va_arg(ap, u_char **);
					*sp = malloc(max_size < size ? max_size : size);
					memcpy(*sp, cp, max_size < size ? max_size : size);
					cp += size;
					break;
				}

				case 'S': {
					u_char *sp = va_arg(ap, u_char *);
					memcpy(sp, cp, max_size < size ? max_size : size);
					cp += size;
					break;       	
				}

				default:	
					assert(!"valid format code");
					break;
				}				

				ret += 1;
			}
		}

		fmt++;
	}
示例#17
0
文件: terra.cpp 项目: zdevito/terra
void terra_pusherror(terra_State * T, const char * fmt, ...) {
    va_list ap;
    va_start(ap,fmt);
    terra_vpusherror(T,fmt,ap);
    va_end(ap);
}
示例#18
0
/*PRINTFLIKE3*/
int
zpool_standard_error_fmt(libzfs_handle_t *hdl, int error, const char *fmt, ...)
{
	va_list ap;

	va_start(ap, fmt);

	if (zfs_common_error(hdl, error, fmt, ap) != 0) {
		va_end(ap);
		return (-1);
	}

	switch (error) {
	case ENODEV:
		zfs_verror(hdl, EZFS_NODEVICE, fmt, ap);
		break;

	case ENOENT:
		zfs_error_aux(hdl,
		    dgettext(TEXT_DOMAIN, "no such pool or dataset"));
		zfs_verror(hdl, EZFS_NOENT, fmt, ap);
		break;

	case EEXIST:
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
		    "pool already exists"));
		zfs_verror(hdl, EZFS_EXISTS, fmt, ap);
		break;

	case EBUSY:
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "pool is busy"));
		zfs_verror(hdl, EZFS_EXISTS, fmt, ap);
		break;

	case ENXIO:
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
		    "one or more devices is currently unavailable"));
		zfs_verror(hdl, EZFS_BADDEV, fmt, ap);
		break;

	case ENAMETOOLONG:
		zfs_verror(hdl, EZFS_DEVOVERFLOW, fmt, ap);
		break;

	case ENOTSUP:
		zfs_verror(hdl, EZFS_POOL_NOTSUP, fmt, ap);
		break;

	case EINVAL:
		zfs_verror(hdl, EZFS_POOL_INVALARG, fmt, ap);
		break;

	case ENOSPC:
	case EDQUOT:
		zfs_verror(hdl, EZFS_NOSPC, fmt, ap);
		return (-1);

	default:
		zfs_error_aux(hdl, strerror(error));
		zfs_verror(hdl, EZFS_UNKNOWN, fmt, ap);
	}

	va_end(ap);
	return (-1);
}
示例#19
0
文件: cosby.c 项目: nicknassar/cosby
void cosby_print_err(char *format, ...){
  va_list ap;
  va_start(ap,format);
  vfprintf(stderr, format, ap);
  va_end(ap);    
}
示例#20
0
文件: fatal.c 项目: Chadi-akel/cere
void fatal_error(int fatal_errno,char *fmt,...)
{
  va_list ap;
  char    *p,cval,*sval,msg[STRLEN];
  char    ibuf[64],ifmt[64];
  int     index,ival,fld,len;
  double  dval;
#ifdef _SPECIAL_VAR_ARG
  int     fatal_errno;
  char    *fmt;
  
  va_start(ap,);
  fatal_errno=va_arg(ap,int);
  fmt=va_arg(ap,char *);
#else
  va_start(ap,fmt);
#endif

  if (fatal_tmp_file) {
    fprintf(stderr,"Cleaning up temporary file %s\n",fatal_tmp_file);
    remove(fatal_tmp_file);
    sfree(fatal_tmp_file);
    fatal_tmp_file = NULL;
  }
  
  len=0;
  bputs(msg,&len,"Fatal error: ",0);
  for (p=fmt; *p; p++) {
    if (*p!='%')
      bputc(msg,&len,*p);
    else {
      p++;
      fld=getfld(&p);
      switch(*p) {
      case 'x':
	ival=va_arg(ap,int);
	sprintf(ifmt,"0x%%%dx",fld);
	sprintf(ibuf,ifmt,(unsigned int)ival);
	for(index=0; (index<(int)strlen(ibuf)); index++)
	  bputc(msg,&len,ibuf[index]);
	break;
      case 'd':
	ival=va_arg(ap,int);
	sprintf(ifmt,"%%%dd",fld);
	sprintf(ibuf,ifmt,ival);
	for(index=0; (index<(int)strlen(ibuf)); index++)
	  bputc(msg,&len,ibuf[index]);
	break;
      case 'f':
	dval=va_arg(ap,double);
	sprintf(ifmt,"%%%df",fld);
	sprintf(ibuf,ifmt,dval);
	for(index=0; (index<(int)strlen(ibuf)); index++)
	  bputc(msg,&len,ibuf[index]);
	break;
      case 'c':
	cval=(char) va_arg(ap,int); /* char is promoted to int */
	bputc(msg,&len,cval);
	break;
      case 's':
	sval=va_arg(ap,char *);
	bputs(msg,&len,sval,fld);
	break;
      default:
	break;
      }
    }
  }
  va_end(ap);
  bputc(msg,&len,'\0');

  quit_gmx(fatal_errno,msg);
}
示例#21
0
void xw_get(WINDOW *w, int field,...)
{
	RECT *r;
	int *parm[4], dummy;
	register int i, parms, handle;
	va_list p;

	va_start(p, field);

	handle = (w == NULL) ? 0 : w->xw_handle;

	switch (field)
	{
	case WF_FIRSTXYWH:
	case WF_NEXTXYWH:
	case WF_FULLXYWH:
	case WF_PREVXYWH:
	  getrect:
		r = va_arg(p, RECT *);
		wind_get(handle, field, &r->x, &r->y, &r->w, &r->h);
		break;
	case WF_WORKXYWH:
		if (handle == 0)
			goto getrect;
		r = va_arg(p, RECT *);

		*r = w->xw_work;

		if (w->xw_menu != NULL)
		{
			int height;

			height = w->xw_menu[w->xw_bar].ob_height + 1;

			r->y += height;
			r->h -= height;
		}
		break;
	case WF_CURRXYWH:
		if (handle == 0)
			goto getrect;

		r = va_arg(p, RECT *);

		r->x = w->xw_size.x;
		r->y = w->xw_size.y;
		r->w = w->xw_size.w;
		r->h = w->xw_size.h;
		break;
	default:
		if ((field >= 1) && (field <= sizeof(xw_get_argtab)))
			parms = xw_get_argtab[(field - 1) & 0x1F];
		else
			parms = 4;

		for (i = 0; i < parms; i++)
			parm[i] = va_arg(p, int *);
		for (;i < 4;i++)
			parm[i] = &dummy;

		wind_get(handle, field, parm[0], parm[1], parm[2], parm[3]);
		break;
	}
	va_end(p);
}
示例#22
0
int opus_decoder_ctl(OpusDecoder *st, int request, ...)
{
   int ret = OPUS_OK;
   va_list ap;
   void *silk_dec;
   CELTDecoder *celt_dec;

   silk_dec = (char*)st+st->silk_dec_offset;
   celt_dec = (CELTDecoder*)((char*)st+st->celt_dec_offset);


   va_start(ap, request);

   switch (request)
   {
   case OPUS_GET_BANDWIDTH_REQUEST:
   {
      opus_int32 *value = va_arg(ap, opus_int32*);
      if (!value)
      {
         goto bad_arg;
      }
      *value = st->bandwidth;
   }
   break;
   case OPUS_GET_FINAL_RANGE_REQUEST:
   {
      opus_uint32 *value = va_arg(ap, opus_uint32*);
      if (!value)
      {
         goto bad_arg;
      }
      *value = st->rangeFinal;
   }
   break;
   case OPUS_RESET_STATE:
   {
      OPUS_CLEAR((char*)&st->OPUS_DECODER_RESET_START,
            sizeof(OpusDecoder)-
            ((char*)&st->OPUS_DECODER_RESET_START - (char*)st));

      celt_decoder_ctl(celt_dec, OPUS_RESET_STATE);
      silk_InitDecoder( silk_dec );
      st->stream_channels = st->channels;
      st->frame_size = st->Fs/400;
   }
   break;
   case OPUS_GET_SAMPLE_RATE_REQUEST:
   {
      opus_int32 *value = va_arg(ap, opus_int32*);
      if (!value)
      {
         goto bad_arg;
      }
      *value = st->Fs;
   }
   break;
   case OPUS_GET_PITCH_REQUEST:
   {
      opus_int32 *value = va_arg(ap, opus_int32*);
      if (!value)
      {
         goto bad_arg;
      }
      if (st->prev_mode == MODE_CELT_ONLY)
         celt_decoder_ctl(celt_dec, OPUS_GET_PITCH(value));
      else
         *value = st->DecControl.prevPitchLag;
   }
   break;
   case OPUS_GET_GAIN_REQUEST:
   {
      opus_int32 *value = va_arg(ap, opus_int32*);
      if (!value)
      {
         goto bad_arg;
      }
      *value = st->decode_gain;
   }
   break;
   case OPUS_SET_GAIN_REQUEST:
   {
       opus_int32 value = va_arg(ap, opus_int32);
       if (value<-32768 || value>32767)
       {
          goto bad_arg;
       }
       st->decode_gain = value;
   }
   break;
   case OPUS_GET_LAST_PACKET_DURATION_REQUEST:
   {
      opus_int32 *value = va_arg(ap, opus_int32*);
      if (!value)
      {
         goto bad_arg;
      }
      *value = st->last_packet_duration;
   }
   break;
   case OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST:
   {
       opus_int32 value = va_arg(ap, opus_int32);
       if(value<0 || value>1)
       {
          goto bad_arg;
       }
       celt_decoder_ctl(celt_dec, OPUS_SET_PHASE_INVERSION_DISABLED(value));
   }
   break;
   case OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST:
   {
       opus_int32 *value = va_arg(ap, opus_int32*);
       if (!value)
       {
          goto bad_arg;
       }
       celt_decoder_ctl(celt_dec, OPUS_GET_PHASE_INVERSION_DISABLED(value));
   }
   break;
   default:
      /*fprintf(stderr, "unknown opus_decoder_ctl() request: %d", request);*/
      ret = OPUS_UNIMPLEMENTED;
      break;
   }

   va_end(ap);
   return ret;
bad_arg:
   va_end(ap);
   return OPUS_BAD_ARG;
}
示例#23
0
文件: log.c 项目: jianglei12138/avahi
void avahi_log(AvahiLogLevel level, const char*format, ...) {
    va_list ap;
    va_start(ap, format);
    avahi_log_ap(level, format, ap);
    va_end(ap);
}
示例#24
0
/*
 * Function name:	tw_cl_create_event
 * Description:		Creates and queues ctlr/CL/OSL AEN's to be
 *			supplied to user-space tools on request.
 *			Also notifies OS Layer.
 * Input:		ctlr	-- ptr to CL internal ctlr context
 *			queue_event-- TW_CL_TRUE --> queue event;
 *				      TW_CL_FALSE--> don't queue event
 *							(simply notify OSL)
 *			event_src  -- source of event
 *			event_code -- AEN/error code
 *			severity -- severity of event
 *			severity_str--Text description of severity
 *			event_desc -- standard string related to the event/error
 *			event_specific_desc -- format string for additional
 *						info about the event
 *			... -- additional arguments conforming to the format
 *				specified by event_specific_desc
 * Output:		None
 * Return value:	None
 */
TW_VOID
tw_cl_create_event(struct tw_cl_ctlr_handle *ctlr_handle,
	TW_UINT8 queue_event, TW_UINT8 event_src, TW_UINT16 event_code,
	TW_UINT8 severity, TW_UINT8 *severity_str, TW_UINT8 *event_desc,
	TW_UINT8 *event_specific_desc, ...)
{
	struct tw_cli_ctlr_context	*ctlr = ctlr_handle->cl_ctlr_ctxt;
	struct tw_cl_event_packet	event_pkt;
	struct tw_cl_event_packet	*event;
	TW_UINT32			aen_head;
	va_list				ap;

	tw_cli_dbg_printf(8, ctlr_handle, tw_osl_cur_func(), "entered");

	if ((ctlr) && (queue_event)) {
		/* Protect access to ctlr->aen_head. */
		tw_osl_get_lock(ctlr_handle, ctlr->gen_lock);

		aen_head = ctlr->aen_head;
		ctlr->aen_head = (aen_head + 1) % ctlr->max_aens_supported;

		/* Queue the event. */
		event = &(ctlr->aen_queue[aen_head]);
		tw_osl_memzero(event->parameter_data,
			sizeof(event->parameter_data));

		if (event->retrieved == TW_CL_AEN_NOT_RETRIEVED)
			ctlr->aen_q_overflow = TW_CL_TRUE;
		event->sequence_id = ++(ctlr->aen_cur_seq_id);
		if ((aen_head + 1) == ctlr->max_aens_supported) {
			tw_cli_dbg_printf(4, ctlr->ctlr_handle,
				tw_osl_cur_func(), "AEN queue wrapped");
			ctlr->aen_q_wrapped = TW_CL_TRUE;
		}

		/* Free access to ctlr->aen_head. */
		tw_osl_free_lock(ctlr_handle, ctlr->gen_lock);
	} else {
		event = &event_pkt;
		tw_osl_memzero(event, sizeof(struct tw_cl_event_packet));
	}

	event->event_src = event_src;
	event->time_stamp_sec = (TW_UINT32)tw_osl_get_local_time();
	event->aen_code = event_code;
	event->severity = severity;
	tw_osl_strcpy(event->severity_str, severity_str);
	event->retrieved = TW_CL_AEN_NOT_RETRIEVED;

	va_start(ap, event_specific_desc);
	tw_osl_vsprintf(event->parameter_data, event_specific_desc, ap);
	va_end(ap);

	event->parameter_len =
		(TW_UINT8)(tw_osl_strlen(event->parameter_data));
	tw_osl_strcpy(event->parameter_data + event->parameter_len + 1,
		event_desc);
	event->parameter_len += (1 + tw_osl_strlen(event_desc));

	tw_cli_dbg_printf(4, ctlr_handle, tw_osl_cur_func(),
		"event = %x %x %x %x %x %x %x\n %s",
		event->sequence_id,
		event->time_stamp_sec,
		event->aen_code,
		event->severity,
		event->retrieved,
		event->repeat_count,
		event->parameter_len,
		event->parameter_data);

	tw_osl_notify_event(ctlr_handle, event);
}
示例#25
0
文件: log.c 项目: jianglei12138/avahi
void avahi_log_warn(const char*format, ...) {
    va_list ap;
    va_start(ap, format);
    avahi_log_ap(AVAHI_LOG_WARN, format, ap);
    va_end(ap);
}
示例#26
0
void logmsg(char *fmt, ...) {
  va_list args;
  va_start(args,fmt);
  (void) vsyslog(LOG_ERR,fmt,args);
  va_end(args);
}
示例#27
0
文件: log.c 项目: jianglei12138/avahi
void avahi_log_info(const char*format, ...) {
    va_list ap;
    va_start(ap, format);
    avahi_log_ap(AVAHI_LOG_INFO, format, ap);
    va_end(ap);
}
示例#28
0
static void
add_encoding(
	unsigned int encoding_index, // index of the encoding in the encodings
				     // array
	unsigned int rb_encoding_type,
	const char *public_name, // public name for the encoding
	unsigned char min_char_size,
	bool single_byte_encoding, // in the encoding a character takes only
				   // one byte
	bool ascii_compatible, // is the encoding ASCII compatible or not
	bool little_endian, // for UTF-16/32, if the encoding is little endian
	... // aliases for the encoding (should no include the public name)
	    // - must end with a NULL
	)
{
    assert(encoding_index < ENCODINGS_COUNT);

    // create an array for the aliases
    unsigned int aliases_count = 0;
    va_list va_aliases;
    va_start(va_aliases, little_endian);
    while (va_arg(va_aliases, const char *) != NULL) {
	++aliases_count;
    }
    va_end(va_aliases);
    const char **aliases = (const char **)
	malloc(sizeof(const char *) * aliases_count);
    assert(aliases != NULL);
    va_start(va_aliases, little_endian);
    for (unsigned int i = 0; i < aliases_count; ++i) {
	aliases[i] = va_arg(va_aliases, const char *);
    }
    va_end(va_aliases);

    // create the MacRuby object
    NEWOBJ(encoding, rb_encoding_t);
    encoding->basic.flags = 0;
    encoding->basic.klass = rb_cEncoding;
    rb_encodings[encoding_index] = encoding;
    GC_RETAIN(encoding); // it should never be deallocated

    // fill the fields
    encoding->index = encoding_index;
    encoding->public_name = public_name;
    encoding->min_char_size = min_char_size;
    encoding->single_byte_encoding = single_byte_encoding;
    encoding->ascii_compatible = ascii_compatible;
    encoding->little_endian = little_endian;
    encoding->aliases_count = aliases_count;
    encoding->aliases = aliases;

    switch (rb_encoding_type) {
	case ENCODING_TYPE_SPECIAL:
	    break;
	case ENCODING_TYPE_UCNV:
	    enc_init_ucnv_encoding(encoding);
	    break;
	default:
	    abort();
    }
}
示例#29
0
	int printf (

/*  SYNOPSIS */
	const char * format,
	...)

/*  FUNCTION
	Formats a list of arguments and prints them to standard out.

	The format string is composed of zero or more directives: ordinary
	characters (not %), which are copied unchanged to the output
	stream; and conversion specifications, each of which results in
	fetching zero or more subsequent arguments Each conversion
	specification is introduced by the character %. The arguments must
	correspond properly (after type promotion) with the conversion
	specifier. After the %, the following appear in sequence:

	\begin{itemize}
	\item Zero or more of the following flags:

	\begin{description}
	\item{#} specifying that the value should be converted to an
	``alternate form''. For c, d, i, n, p, s, and u conversions, this
	option has no effect. For o conversions, the precision of the
	number is increased to force the first character of the output
	string to a zero (except if a zero value is printed with an
	explicit precision of zero). For x and X conversions, a non-zero
	result has the string `0x' (or `0X' for X conversions) prepended to
	it. For e, E, f, g, and G conversions, the result will always
	contain a decimal point, even if no digits follow it (normally, a
	decimal point appears in the results of those conversions only if a
	digit follows). For g and G conversions, trailing zeros are not
	removed from the result as they would otherwise be.

	\item{0} specifying zero padding. For all conversions except n, the
	converted value is padded on the left with zeros rather than
	blanks. If a precision is given with a numeric conversion (d, i, o,
	u, i, x, and X), the 0 flag is ignored.

	\item{-} (a negative field width flag) indicates the converted
	value is to be left adjusted on the field boundary. Except for n
	conversions, the converted value is padded on the right with
	blanks, rather than on the left with blanks or zeros. A -
	overrides a 0 if both are given.

	\item{ } (a space) specifying that a blank should be left before a
	positive number produced by a signed conversion (d, e, E, f, g, G,
	or i). + specifying that a sign always be placed before a number
	produced by a signed conversion. A + overrides a space if both are
	used.

	\item{'} specifying that in a numerical argument the output is to
	be grouped if the locale information indicates any. Note that many
	versions of gcc cannot parse this option and will issue a warning.

	\end{description}

	\item An optional decimal digit string specifying a minimum field
	width. If the converted value has fewer characters than the field
	width, it will be padded with spaces on the left (or right, if the
	left-adjustment flag has been given) to fill out the field width.

	\item An optional precision, in the form of a period (`.') followed
	by an optional digit string. If the digit string is omitted, the
	precision is taken as zero. This gives the minimum number of digits
	to appear for d, i, o, u, x, and X conversions, the number of
	digits to appear after the decimal-point for e, E, and f
	conversions, the maximum number of significant digits for g and G
	conversions, or the maximum number of characters to be printed from
	a string for s conversions.

	\item The optional character h, specifying that a following d, i,
	o, u, x, or X conversion corresponds to a short int or unsigned
	short int argument, or that a following n conversion corresponds to
	a pointer to a short int argument.

	\item The optional character l (ell) specifying that a following d,
	i, o, u, x, or X conversion applies to a pointer to a long int or
	unsigned long int argument, or that a following n conversion
	corresponds to a pointer to a long int argument. Linux provides a
	non ANSI compliant use of two l flags as a synonym to q or L. Thus
	ll can be used in combination with float conversions. This usage
	is, however, strongly discouraged.

	\item The character L specifying that a following e, E,
	f, g, or G conversion corresponds to a long double
	argument, or a following d, i, o, u, x, or X conversion corresponds to a long long argument. Note
	that long long is not specified in ANSI C and
	therefore not portable to all architectures.

	\item The optional character q. This is equivalent to L. See the
	STANDARDS and BUGS sections for comments on the use of ll, L, and
	q.

	\item A Z character specifying that the following integer (d, i, o,
	u, i, x, and X), conversion corresponds to a size_t argument.

	\item A character that specifies the type of conversion to be
	applied.

	A field width or precision, or both, may be indicated by an
	asterisk `*' instead of a digit string. In this case, an int
	argument supplies the field width or precision. A negative field
	width is treated as a left adjustment flag followed by a positive
	field width; a negative precision is treated as though it were
	missing.

	The conversion specifiers and their meanings are:

	\begin{description}
	\item{diouxX} The int (or appropriate variant) argument is
	converted to signed decimal (d and i), unsigned octal (o, unsigned
	decimal (u, or unsigned hexadecimal (x and X) notation. The letters
	abcdef are used for x conversions; the letters ABCDEF are used for
	X conversions. The precision, if any, gives the minimum number of
	digits that must appear; if the converted value requires fewer
	digits, it is padded on the left with zeros.

	\item{eE} The double argument is rounded and converted in the style
	[<->]d.dddedd where there is one digit before the decimal-point
	character and the number of digits after it is equal to the
	precision; if the precision is missing, it is taken as 6; if the
	precision is zero, no decimal-point character appears. An E
	conversion uses the letter E (rather than e) to introduce the
	exponent. The exponent always contains at least two digits; if the
	value is zero, the exponent is 00.

	\item{f} The double argument is rounded and converted to decimal
	notation in the style [-]ddd.ddd, where the number of digits after
	the decimal-point character is equal to the precision
	specification. If the precision is missing, it is taken as 6; if
	the precision is explicitly zero, no decimal-point character
	appears. If a decimal point appears, at least one digit appears
	before it.

	\item{g} The double argument is converted in style f or e (or E for
	G conversions). The precision specifies the number of significant
	digits. If the precision is missing, 6 digits are given; if the
	precision is zero, it is treated as 1. Style e is used if the
	exponent from its conversion is less than -4 or greater than or
	equal to the precision. Trailing zeros are removed from the
	fractional part of the result; a decimal point appears only if it
	is followed by at least one digit.

	\item{c} The int argument is converted to an unsigned char, and the
	resulting character is written.

	\item{s} The ``char *'' argument is expected to be a pointer to an
	array of character type (pointer to a string). Characters from the
	array are written up to (but not including) a terminating NUL
	character; if a precision is specified, no more than the number
	specified are written. If a precision is given, no null character
	need be present; if the precision is not specified, or is greater
	than the size of the array, the array must contain a terminating
	NUL character.

	\item{p} The ``void *'' pointer argument is printed in hexadecimal
	(as if by %#x or %#lx).

	\item{n} The number of characters written so far is stored into the
	integer indicated by the ``int *'' (or variant) pointer argument.
	No argument is converted.

	\item{%} A `%' is written. No argument is converted. The complete
	conversion specification is `%%'.

	\end{description}
	\end{itemize}

	In no case does a non-existent or small field width cause
	truncation of a field; if the result of a conversion is wider than
	the field width, the field is expanded to contain the conversion
	result.

    INPUTS
	format - Format string as described above
	... - Arguments for the format string

    RESULT
	The number of characters written to stdout or EOF on error.

    NOTES

    EXAMPLE
	To print a date and time in the form `Sunday, July 3,
	10:02', where weekday and month are pointers to strings:

	    #include <stdio.h>

	    fprintf (stdout, "%s, %s %d, %.2d:%.2d\n",
		    weekday, month, day, hour, min);

	To print to five decimal places:

	    #include <math.h>
	    #include <stdio.h>

	    fprintf (stdout, "pi = %.5f\n", 4 * atan(1.0));

	To allocate a 128 byte string and print into it:

	    #include <stdio.h>
	    #include <stdlib.h>
	    #include <stdarg.h>

	    char *newfmt(const char *fmt, ...)
	    {
		char *p;
		va_list ap;

		if ((p = malloc(128)) == NULL)
		    return (NULL);

		va_start(ap, fmt);

		(void) vsnprintf(p, 128, fmt, ap);

		va_end(ap);

		return (p);
	    }

    BUGS
	All functions are fully ANSI C3.159-1989 conformant, but provide
	the additional flags q, Z and ' as well as an additional behaviour
	of the L and l flags. The latter may be considered to be a bug, as
	it changes the behaviour of flags defined in ANSI C3.159-1989.

	The effect of padding the %p format with zeros (either by the 0
	flag or by specifying a precision), and the benign effect (i.e.,
	none) of the # flag on %n and %p conversions, as well as
	nonsensical combinations such as are not standard; such
	combinations should be avoided.

	Some combinations of flags defined by ANSI C are not making sense
	in ANSI C (e.g. %Ld). While they may have a well-defined behaviour
	on Linux, this need not to be so on other architectures. Therefore
	it usually is better to use flags that are not defined by ANSI C at
	all, i.e. use q instead of L in combination with diouxX conversions
	or ll. The usage of q is not the same as on BSD 4.4, as it may be
	used in float conversions equivalently to L.

	Because sprintf and vsprintf assume an infinitely long string,
	callers must be careful not to overflow the actual space; this is
	often impossible to assure.

    SEE ALSO
	fprintf(), vprintf(), vfprintf(), sprintf(), vsprintf(),
	vsnprintf()

    INTERNALS

******************************************************************************/
{
    int     retval;
    va_list args;

    va_start (args, format);

    retval = vfprintf (stdout, format, args);

    va_end (args);

    fflush (stdout);

    return retval;
} /* printf */
示例#30
0
void
mowgli_proctitle_set(const char *fmt, ...)
{
#ifndef MOWGLI_SETPROC_USE_NONE
	va_list va;

#if defined(MOWGLI_SETPROC_USE_CHANGE_ARGV) || defined(MOWGLI_SETPROC_USE_CLOBBER_ARGV)
	if (!save_argv)
		return;
#endif

	va_start(va, fmt);
	vsnprintf(ps_buffer, ps_buffer_size, fmt, va);
	va_end(va);

	return_if_fail(*ps_buffer == '\0');

	ps_buffer_cur_len = ps_buffer_fixed_size = strlen(ps_buffer);

#ifdef MOWGLI_SETPROC_USE_CHANGE_ARGV
	save_argv[0] = ps_buffer;
	save_argv[1] = NULL;
#endif

#ifdef MOWGLI_SETPROC_USE_CLOBBER_ARGV
	for (int i = 1; i < save_argc; i++)
		save_argv[i] = ps_buffer + ps_buffer_size;

	/* Pad unused bytes */
	memset(ps_buffer + ps_buffer_cur_len, PS_PADDING, ps_buffer_size - ps_buffer_cur_len + 1);
#endif

#ifdef MOWGLI_SETPROC_USE_SETPROCTITLE
	setproctitle("%s", ps_buffer);
#endif

#ifdef MOWGLI_SETPROC_USE_PRCTL
	/* Limit us to 16 chars to be safe */
	char procbuf[16];
	mowgli_strlcpy(procbuf, ps_buffer, sizeof(procbuf));
	prctl(PR_SET_NAME, procbuf, 0, 0, 0);
#endif

#ifdef MOWGLI_SETPROC_USE_PSTAT
	union pstun pst;

	pst.pst_command = ps_buffer;
	pstat(PSTAT_SETCMD, pst, ps_buffer_cur_len, 0, 0);
#endif   /* MOWGLI_SETPROC_USE_PSTAT */

#ifdef MOWGLI_SETPROC_USE_PS_STRINGS
	PS_STRINGS->ps_nargvstr = 1;
	PS_STRINGS->ps_argvstr = ps_buffer;
#endif   /* MOWGLI_SETPROC_USE_PS_STRINGS */

#ifdef MOWGLI_SETPROC_USE_WIN32
	/*
	 * Win32 does not support showing any changed arguments. To make it at
	 * all possible to track which backend is doing what, we create a
	 * named object that can be viewed with for example Process Explorer.
	 */
	static HANDLE ident_handle = INVALID_HANDLE_VALUE;
	char name[PS_BUFFER_SIZE + 32];

	if (ident_handle != INVALID_HANDLE_VALUE)
		CloseHandle(ident_handle);

	sprintf(name, "mowgli_ident(%d): %s", getpid(), ps_buffer);

	ident_handle = CreateEvent(NULL, TRUE, FALSE, name);
#endif   /* MOWGLI_SETPROC_USE_WIN32 */
#endif   /* not MOWGLI_SETPROC_USE_NONE */
}