Exemplo n.º 1
0
/**
 * Print server details to a DCB
 *
 * Designed to be called within a debugger session in order
 * to display all active servers within the gateway
 */
void
dprintServer(DCB *dcb, SERVER *server)
{
char		*stat;
SERVER_PARAM	*param;

	dcb_printf(dcb, "Server %p (%s)\n", server, server->unique_name);
	dcb_printf(dcb, "\tServer:				%s\n", server->name);
	stat = server_status(server);
	dcb_printf(dcb, "\tStatus:               		%s\n", stat);
	free(stat);
	dcb_printf(dcb, "\tProtocol:			%s\n", server->protocol);
	dcb_printf(dcb, "\tPort:				%d\n", server->port);
	if (server->server_string)
		dcb_printf(dcb, "\tServer Version:\t\t\t%s\n", server->server_string);
	dcb_printf(dcb, "\tNode Id:			%d\n", server->node_id);
	dcb_printf(dcb, "\tMaster Id:			%d\n", server->master_id);
	if (server->slaves) {
		int i;
		dcb_printf(dcb, "\tSlave Ids:			");
		for (i = 0; server->slaves[i]; i++)
		{
			if (i == 0)
				dcb_printf(dcb, "%li", server->slaves[i]);
			else
				dcb_printf(dcb, ", %li ", server->slaves[i]);
		}
		dcb_printf(dcb, "\n");
	}
	dcb_printf(dcb, "\tRepl Depth:			%d\n", server->depth);
	if (SERVER_IS_SLAVE(server) || SERVER_IS_RELAY_SERVER(server)) {
		if (server->rlag >= 0) {
			dcb_printf(dcb, "\tSlave delay:\t\t%d\n", server->rlag);
		}
	}
	if (server->node_ts > 0) {
		struct tm result;
		char 	 buf[40];
		dcb_printf(dcb, "\tLast Repl Heartbeat:\t%s",
			asctime_r(localtime_r((time_t *)(&server->node_ts), &result), buf));
	}
	if ((param = server->parameters) != NULL)
	{
		dcb_printf(dcb, "\tServer Parameters:\n");
		while (param)
		{
			dcb_printf(dcb, "\t\t%-20s\t%s\n", param->name,
								param->value);
			param = param->next;
		}
	}
	dcb_printf(dcb, "\tNumber of connections:		%d\n",
						server->stats.n_connections);
	dcb_printf(dcb, "\tCurrent no. of conns:		%d\n",
						server->stats.n_current);
        dcb_printf(dcb, "\tCurrent no. of operations:	%d\n", server->stats.n_current_ops);
}
Exemplo n.º 2
0
char           *
ctime(const time_t * timeptr)
{
	struct tm       calendar;

	localtime_r(timeptr, &calendar);
	asctime_r(&calendar, __asc_store);
	return __asc_store;
}
Exemplo n.º 3
0
    virtual void wrapup()
    {
        info("done\n");

        info("sorting by balance ...");

            CompareAddr compare;
            auto e = allAddrs.end();
            auto s = allAddrs.begin();
            std::sort(s, e, compare);

        info("done\n");

        uint64_t nbRestricts = (uint64_t)restrictMap.size();
        if(0==nbRestricts) info("dumping all balances ...");
        else               info("dumping balances for %" PRIu64 " addresses ...", nbRestricts);

        uint64_t i = 0;
        uint64_t nonZeroCnt = 0;
        while(likely(s<e)) {

            Addr *addr = *(s++);
            if(0!=nbRestricts) {
                auto r = restrictMap.find(addr->hash.v);
                if(restrictMap.end()==r) continue;
            }

            printf("%24.8f ", (1e-8)*addr->sum);
            showHex(addr->hash.v, kRIPEMD160ByteSize, false);
            if(0<addr->sum) ++nonZeroCnt;

            if(i<5000 || 0!=nbRestricts) {
                uint8_t buf[64];
                hash160ToAddr(buf, addr->hash.v);
                printf(" %s", buf);
            }

            struct tm gmTime;
            time_t last = addr->lastTouched;
            gmtime_r(&last, &gmTime);

            char timeBuf[256];
            asctime_r(&gmTime, timeBuf);

            size_t sz =strlen(timeBuf);
            if(0<sz) timeBuf[sz-1] = 0;

            printf(" %s\n", timeBuf);
            ++i;
        }
        info("done\n");

        info("found %" PRIu64 " addresses with non zero balance", nonZeroCnt);
        info("found %" PRIu64 " addresses in total", (uint64_t)allAddrs.size());
        info("shown:%" PRIu64 " addresses", (uint64_t)i);
    }
Exemplo n.º 4
0
void tmplput_nowstr(StrBuf *Target, WCTemplputParams *TP)
{
	char buf[64];
	long bufused;
	time_t now;
	
	now = time(NULL);
#ifdef HAVE_SOLARIS_LOCALTIME_R
	asctime_r(localtime(&now), buf, sizeof(buf));
#else
	asctime_r(localtime(&now), buf);
#endif
	bufused = strlen(buf);
	if ((bufused > 0) && (buf[bufused - 1] == '\n')) {
		buf[bufused - 1] = '\0';
		bufused --;
	}
	StrEscAppend(Target, NULL, buf, 0, 0);
}
Exemplo n.º 5
0
int test( void )
{
  char      *buffer_pointer;
  struct tm  timestruct;
  char       buffer[ 80 ];

  buffer_pointer = asctime_r( &timestruct, buffer );

  return (buffer_pointer != NULL);
}
void ISocketCommunication::getTimestamp(char* strTimeStamp)
{
  time_t l_time;
  struct tm result;
  if( !strTimeStamp ) return;
  
  l_time = time(NULL);
  localtime_r(&l_time, &result); 
  asctime_r(&result, strTimeStamp);
}
Exemplo n.º 7
0
Arquivo: ltime.c Projeto: xumjbn/alpha
/*
 * strtime = time.asctime({sec=, min=, ...}) 
 */
static int ltime_asctime(lua_State *L)
{
    struct tm tm;
    lua_settop(L, 1);
    gettime_from_table(L, &tm);
    char buf[32];
    asctime_r(&tm, buf);
    lua_pushlstring(L, buf, strlen(buf) - 1);
    return 1;
}
Exemplo n.º 8
0
string getCurrentTime() {
	time_t rawTime;
	tm * timeInfo = new tm;

	time ( &rawTime );
	localtime_r(&rawTime, timeInfo);

	char buff[100];
	asctime_r(timeInfo, buff);
	string buff_str = string(buff);
	return buff_str.substr(0, buff_str.length() - 1);
}
Exemplo n.º 9
0
char * asctime
    (
    const struct tm *timeptr	/* broken-down time */
    )
    {
    size_t           len = sizeof (ASCBUF);
    static char      asctimeBuf [sizeof (ASCBUF)];

    asctime_r (timeptr, asctimeBuf, &len);

    return (asctimeBuf);
    }
Exemplo n.º 10
0
    static void gmTime(
        char *timeBuf,
        const time_t &last
    )
    {
        struct tm gmTime;
        gmtime_r(&last, &gmTime);
        asctime_r(&gmTime, timeBuf);

        size_t sz =strlen(timeBuf);
        if(0<sz) timeBuf[sz-1] = 0;
    }
Exemplo n.º 11
0
void display_sysid (void)
{
	struct nios_sysid_t *sysid = (struct nios_sysid_t *)CONFIG_SYS_NIOS_SYSID_BASE;
	struct tm t;
	char asc[32];
	time_t stamp;

	stamp = readl (&sysid->timestamp);
	localtime_r (&stamp, &t);
	asctime_r (&t, asc);
	printf ("SYSID : %08lx, %s", readl (&sysid->id), asc);

}
Exemplo n.º 12
0
/**
 * Print details of an individual session
 *
 * @param session       Session to print
 */
void
printSession(SESSION *session)
{
    struct tm result;
    char timebuf[40];

    printf("Session %p\n", session);
    printf("\tState:        %s\n", session_state(session->state));
    printf("\tService:      %s (%p)\n", session->service->name, session->service);
    printf("\tClient DCB:   %p\n", session->client_dcb);
    printf("\tConnected:    %s",
           asctime_r(localtime_r(&session->stats.connect, &result), timebuf));
}
Exemplo n.º 13
0
	/**
	 * Prettifies and prints the date to an output stream.
	 * @param os The output stream.
	 * @param axis The axis.
	 */
	friend std::ostream &operator<<(std::ostream &os,
			const DateTime &dateTime) {
		// Create string
		char buffer[26];
		asctime_r(&dateTime.details, buffer);

		// Remove new line
		buffer[std::strlen(buffer) - 1] = '\0';

		// Print and return
		os << buffer;
		return os;
	}
Exemplo n.º 14
0
/* Print a message in "mboxrd" format as documented, for example,
 * here:
 *
 * http://qmail.org/qmail-manual-html/man5/mbox.html
 */
static notmuch_status_t
format_part_mbox (const void *ctx, unused (sprinter_t *sp), mime_node_t *node,
		  unused (int indent),
		  unused (const notmuch_show_params_t *params))
{
    notmuch_message_t *message = node->envelope_file;

    const char *filename;
    FILE *file;
    const char *from;

    time_t date;
    struct tm date_gmtime;
    char date_asctime[26];

    char *line = NULL;
    size_t line_size;
    ssize_t line_len;

    if (!message)
	INTERNAL_ERROR ("format_part_mbox requires a root part");

    filename = notmuch_message_get_filename (message);
    file = fopen (filename, "r");
    if (file == NULL) {
	fprintf (stderr, "Failed to open %s: %s\n",
		 filename, strerror (errno));
	return NOTMUCH_STATUS_FILE_ERROR;
    }

    from = notmuch_message_get_header (message, "from");
    from = _extract_email_address (ctx, from);

    date = notmuch_message_get_date (message);
    gmtime_r (&date, &date_gmtime);
    asctime_r (&date_gmtime, date_asctime);

    printf ("From %s %s", from, date_asctime);

    while ((line_len = getline (&line, &line_size, file)) != -1 ) {
	if (_is_from_line (line))
	    putchar ('>');
	printf ("%s", line);
    }

    printf ("\n");

    fclose (file);

    return NOTMUCH_STATUS_SUCCESS;
}
Exemplo n.º 15
0
static void
alarm_print(_Alarm *a)
{
	char buf[STD_ASCTIME_BUF_SIZE];
	struct tm tm;

	gmtime_r(&a->expiry, &tm);
	asctime_r(&tm, buf);

	SLEEPDLOG_DEBUG("(%s,%s) set alarm id %d @ %s",
	                a->serviceName ? : "null",
	                a->applicationName ? : "null",
	                a->id, buf);
}
Exemplo n.º 16
0
int mprAsctime(MprCtx ctx, char *buf, int bufsize, const struct tm *timeptr)
{
    char	*cp;
    char	localBuf[80];

    cp = asctime_r(timeptr, localBuf);
    if ((int) strlen(cp) >= bufsize) {
        mprAssert(0);
        return MPR_ERR_WONT_FIT;
    }
    mprStrcpy(buf, bufsize, cp);

    return strlen(buf);
}
Exemplo n.º 17
0
  static char* make_local_time(uint32_t t_arg) {
    /* From asctime(1): The asctime_r() function does the same [as
     * asctime], but stores the string in a user-supplied buffer which
     * should have room for at least 26 bytes. */
    char* ret = new char[27];
    time_t t = t_arg;

    asctime_r(localtime(&t), ret);

    assert(ret != 0 && strlen(ret) > 0);

    // Remove terminating \n. Who comes up with these crap APIs?
    ret[strlen(ret) - 1] = '\0';

    return ret;
  }
Exemplo n.º 18
0
/**
 * Routine to print the debug messages with timestamp.
 *
 * @param type the type of the debug
 * @param level and the level of the debug message (0=always shown)
 * @param fmt printf-style format string, followed by additional parameter
 *
 * @return the number of characters printed from the debug message
 * @see debug_dump
 */
int
debug(debug_type_t type, int level, const char *fmt, ...)
{
  va_list ap;
  int result = 0;
  //struct tm *tm;
  struct timeval tv;
  char date_buf[256];

  if (type == 0) {
    type = DBG_ALL;
  }

  if(is_debug_on(type, level)) {

    if (show_timestamp_in_debugs) {
      gettimeofday(&tv, NULL);
    } else {
      memset(&tv, 0, sizeof(struct timeval));
    }
    asctime_r(localtime(&tv.tv_sec), date_buf);
    date_buf[strlen(date_buf) - 6] = 0;

    if(debug_needs_erase) {
      fprintf(stderr, "\r");
      debug_needs_erase = 0;
    }


    fprintf(stderr, "%s.%06d LOG-%4s-%04d: ", date_buf, (int) tv.tv_usec,
            type->id, level);
    va_start(ap, fmt);
    result = vfprintf(stderr, fmt, ap);
    /* CONSOLEXXX

    if(need_console_debugs()) {
      console_printf("\n%s.%06d LOG-%4s-%04d: ", date_buf, (int) tv.tv_usec,
                     type->id, level);
      console_vprintf(fmt, ap);
      console_putstr("\n");
    }
    */
    va_end(ap);
    fprintf(stderr, "\n");
  }
  return result;
}
Exemplo n.º 19
0
void
mpc_log_core(const char *file, int line, int level, int err, 
    const char *fmt, ...)
{
    mpc_logger_t    *l = &mpc_logger;
    uint8_t          errstr[MPC_LOG_MAX_LEN];
    uint8_t         *p, *last;
    va_list          args;
    struct tm        local;
    time_t           t;
    ssize_t          n;

    if (l->fd < 0 || level > l->level) {
        return;
    }

    last = errstr + MPC_LOG_MAX_LEN;
    p = errstr;

    *p++ = '[';

    t = time(NULL);
    localtime_r(&t, &local);
    asctime_r(&local, (char *)p);
    p += 24;

    p = mpc_slprintf(p, last, "] %s:%d [%V] ", file, line, &err_levels[level]);

    va_start(args, fmt);
    p = mpc_vslprintf(p, last, fmt, args);
    va_end(args);

    if (err) {
        p = mpc_log_errno(p, last, err);
    }

    if (p > last - 1) {
        p = last - 1;
    }

    *p++ = LF;

    n = write(l->fd, errstr, p - errstr);
    if (n < 0) {
        l->nerror++;
    }
}
Exemplo n.º 20
0
status_t show_file_list(http_response page, const char *desc, list lst)
{
    list_iterator i;
    char buf[100];
    struct tm t;

    const char *table_start =
        "<table columns='2' border='1' borderwidth='2'>\n"
        "<th>File name</th>\n"
        "<th>Alias/URI</th>\n"
        "<th>Size</th>\n"
        "<th>Last modified</th>\n";

    const char *table_end =
        "</table>\n";

    if (!response_p(page, desc))
        return failure;

    if (!response_add(page, table_start))
        return failure;

    for (i = list_first(lst); !list_end(i); i = list_next(i)) {
        fileinfo fi = list_get(i);
        const struct stat *pst = fileinfo_stat(fi);

        verbose(3, "Adding table td for file %s\n", fileinfo_alias(fi));
        if (!response_add(page, "<tr>\n")
        || !response_td(page, fileinfo_name(fi))
        || !response_td(page, fileinfo_alias(fi)))
            return failure;

        sprintf(buf, "%d", (int)pst->st_size);
        if (!response_td(page, buf))
            return failure;

        localtime_r(&pst->st_mtime, &t);
        asctime_r(&t, buf);
        if (!response_td(page, buf) || !response_add(page, "</tr>\n"))
            return failure;
    }

    if (!response_add(page, table_end))
        return failure;

    return success;
}
Exemplo n.º 21
0
static char *
log_mgmt_timestamp(char *sz_ts)
{
    struct timeval  tval;
    time_t	    t_timep;
    char	    year[6];
    int		    retval;

    /* Sanity test */
    if (!sz_ts) return(NULL);

    /* Get the timeval value */
    retval = gettimeofday(&tval, NULL);
    if (0 == retval) {
	/* Now create the timestamp string */
	t_timep = tval.tv_sec;
	sz_ts[0] = '[';
	sz_ts[1] = '\0';
	if (NULL != asctime_r(localtime(&t_timep), &sz_ts[1])) {
	    char *cp;

	    /* Replace the \n with \0 */
	    cp = strchr(sz_ts, '\n');
	    if (cp) *cp = '\0';

	    cp = strrchr(sz_ts, ' ');
	    strncpy(year, cp+1, 6);
	    year[5] = '\0';	// safety

	    /* Fill-in millisecond & year
	     * period = 1
	     * millisecond time = 3
	     * space = 1
	     * year = 4
	     * end bracket = 1
	     * eof-of-line = 1 */
	    snprintf(cp, 11, ".%03d %s]", (int)tval.tv_usec/1000, year);
	} else
	    strcpy(sz_ts, "<gettime failed>");
    } else {
	/* gettimeofday has failed */
	strcpy(sz_ts, "<gettime failed>");
    }

    return sz_ts;
}	/* end of nvsd_mgmt_timestamp() */
Exemplo n.º 22
0
SimGroupAlarm * sim_group_alarm_new (unsigned int timeout, const gchar *key){
	SimGroupAlarm *p = NULL;
	GString	*gkey;
	struct tm tvalue;
	char timebuf[2048];

	g_return_val_if_fail (key != NULL, NULL);
	if ( (gkey = g_string_new (key)) != NULL){ 
		if (timeout < 3601 ){
			do{
				p = g_object_new (SIM_TYPE_GROUP_ALARM, NULL);
				p->_priv->tstart = time(NULL);
				p->_priv->tend = time(NULL) + timeout;
				p->_priv->alarmsha1 = NULL;
				if (gmtime_r (&p->_priv->tstart,&tvalue) == NULL){
					g_object_unref (G_OBJECT (p));
					p = NULL;
					break; /* Out */
				}
				/* Now obtain the string for the alarm hash  in SimEvent*/
				if (asctime_r (&tvalue,timebuf) == NULL){
					g_object_unref (G_OBJECT (p));
					p = NULL;
					break;
				}
				g_string_append_printf (gkey,"%s|%s",key,timebuf);
				if  ( (p->_priv->alarmsha1 = g_compute_checksum_for_string (G_CHECKSUM_SHA1, gkey->str,-1)) == NULL){
					g_object_unref (G_OBJECT (p));
					p = NULL;
					break;
				}
				
				
			}while (0);

		}else{
			g_warning ("Max timeout is 3600 seconds");
		}
	}
	if (gkey)
		g_string_free (gkey, TRUE);
	if (p == NULL)
		g_warning ("Can't creatae SimGroupAlarm object\n");
	return p;
}
Exemplo n.º 23
0
// mostly the cvs one...
static bool unmodified(const struct stat & sb, const char* ts)
{
   TDEBUG_ENTER("unmodified");
   struct tm tmbuf;
   char timebuf[30];
   char* cp;
   struct tm *tm_p;
   struct tm local_tm;
   /* We want to use the same timestamp format as is stored in the
   st_mtime.  For unix (and NT I think) this *must* be universal
   time (UT), so that files don't appear to be modified merely
   because the timezone has changed.  For VMS, or hopefully other
   systems where gmtime returns NULL, the modification time is
   stored in local time, and therefore it is not possible tcause
   st_mtime to be out of sync by changing the timezone.  */
   tm_p = gmtime_r(&sb.st_mtime, &tmbuf);
   if (tm_p)
   {
      memcpy (&local_tm, tm_p, sizeof (local_tm));
      cp = asctime_r(&local_tm, timebuf);  /* copy in the modify time */
   }
   else
      cp = ctime_r(&sb.st_mtime, timebuf);

   if (!cp)
      return true;

   cp[24] = 0;

#if defined(_MSC_VER) || defined(__GNUWIN32__)
   /* Work around non-standard asctime() and ctime() in MS VC++ and mingw
   These return '01' instead of ' 1' for the day of the month. */
   if (
      (strlen(ts) > 8) &&
      ((cp[8] == '0' && ts[8] == ' ') ||
      (cp[8] == ' ' && ts[8] == '0'))
   ) {
      cp[8] = ts[8];
   }
#endif
   
   TDEBUG_TRACE("Timestamp: " << ts);
   TDEBUG_TRACE("Filetime : " << cp);
   return strcmp(cp, ts) == 0;
}
Exemplo n.º 24
0
static sexp sexp_time_3e_string_stub (sexp ctx, sexp self, sexp_sint_t n, sexp arg0) {
  char *err;
  char tmp1[64];
  sexp res;
  sexp_gc_var1(res1);
  if (! (sexp_pointerp(arg0) && (sexp_pointer_tag(arg0) == sexp_unbox_fixnum(sexp_opcode_arg1_type(self)))))
    return sexp_type_exception(ctx, self, sexp_unbox_fixnum(sexp_opcode_arg1_type(self)), arg0);
  sexp_gc_preserve1(ctx, res1);
  err = asctime_r((struct tm*)sexp_cpointer_value(arg0), tmp1);
  if (!err) {
  res = SEXP_FALSE;
  } else {
  res1 = sexp_c_string(ctx, tmp1, -1);
  res = res1;
  }
  sexp_gc_release1(ctx);
  return res;
}
Exemplo n.º 25
0
Arquivo: time.c Projeto: mikekap/wine
/*********************************************************************
 *		_wasctime (MSVCRT.@)
 */
MSVCRT_wchar_t * CDECL MSVCRT__wasctime(const struct MSVCRT_tm *mstm)
{
    thread_data_t *data = msvcrt_get_thread_data();
    struct tm tm;
    char buffer[30];

    msvcrt_tm_to_unix( &tm, mstm );

    if (!data->wasctime_buffer)
        data->wasctime_buffer = MSVCRT_malloc( 30*sizeof(MSVCRT_wchar_t) ); /* ought to be enough */
#ifdef HAVE_ASCTIME_R
    asctime_r( &tm, buffer );
#else
    strcpy( buffer, asctime(&tm) );
#endif
    MultiByteToWideChar( CP_UNIXCP, 0, buffer, -1, data->wasctime_buffer, 30 );
    return data->wasctime_buffer;
}
Exemplo n.º 26
0
void PrintLog(FILE *fp, const char *format...)
{
    int len = 0;
    va_list ap;
    va_start(ap,format);    
    char buffer[2048] = {0};
    len = vsnprintf(buffer, sizeof(buffer), format, ap);
    buffer[len] = 0;
    char timebuf[256] = {0};
    struct tm tmv;
    time_t timev = time(NULL);
    localtime_r(&timev, &tmv);
    asctime_r(&tmv, timebuf);
    fprintf(fp, "%s", timebuf);
    fprintf(fp, "%s", buffer);
    va_end(ap);
    fflush(fp);
}
Exemplo n.º 27
0
/* This routine runs along the task list and executes any job that wants
 * to be run.
 */
static inline void check_runs(struct tm *now)
{
	centry	 task;
	int	 pid;
	char    *av[5];
	char     s[26];
	char	*q;

	if (tasklist == NULL)
		return;
	for (task = tasklist; task != NULL; task = task->next) {
		if (bit_test(task->minutes, now->tm_min) &&
		    bit_test(task->hours, now->tm_hour) &&
		    bit_test(task->months, now->tm_mon+1) &&
		    bit_test(task->dom, now->tm_mday) &&
		    bit_test(task->dow, now->tm_wday)) {
			asctime_r(now, s);
			q = strchr(s, '\n');
			if (q != NULL)
				*q = '\0';
			log3(s, " Running: ", task->prog);
			av[0] = "cron-parent";		/* Build the cron-parent's argv structure */
			av[1] = task->prog;
			av[2] = itoa(task->user);
			av[3] = task->username;
			av[4] = NULL;

			pid = vfork();
			if (pid == 0) {	/* Child */
				/* This job is ready to run.  Exec the special cron parent
				 * process which actually runs the job.
				 */

				//execve("/bin/cron", av, task->environ); 
				/*Tony*/
				execve("/usr/sbin/crond", av, task->environ);
				error("Unable to exec task: cron-parent");
				_exit(0);
			}
			if (pid < 0)
				error2("Unable to exec task: ", task->prog);
		}
	}
}
Exemplo n.º 28
0
/* Print a message in "mboxrd" format as documented, for example,
 * here:
 *
 * http://qmail.org/qmail-manual-html/man5/mbox.html
 */
static void
format_message_mbox (const void *ctx,
		     notmuch_message_t *message,
		     unused (int indent))
{
    const char *filename;
    FILE *file;
    const char *from;

    time_t date;
    struct tm date_gmtime;
    char date_asctime[26];

    char *line = NULL;
    size_t line_size;
    ssize_t line_len;

    filename = notmuch_message_get_filename (message);
    file = fopen (filename, "r");
    if (file == NULL) {
	fprintf (stderr, "Failed to open %s: %s\n",
		 filename, strerror (errno));
	return;
    }

    from = notmuch_message_get_header (message, "from");
    from = _extract_email_address (ctx, from);

    date = notmuch_message_get_date (message);
    gmtime_r (&date, &date_gmtime);
    asctime_r (&date_gmtime, date_asctime);

    printf ("From %s %s", from, date_asctime);

    while ((line_len = getline (&line, &line_size, file)) != -1 ) {
	if (_is_from_line (line))
	    putchar ('>');
	printf ("%s", line);
    }

    printf ("\n");

    fclose (file);
}
Exemplo n.º 29
0
static void
alarm_save(_Alarm *a, FILE *file)
{
	char buf[STD_ASCTIME_BUF_SIZE];
	struct tm tm;

	gmtime_r(&a->expiry, &tm);

	asctime_r(&tm, buf);
	g_strchomp(buf);

	fprintf(file, "<alarm id='%d' expiry='%ld' calendar='%d'"
	        " key='%s'"
	        " expiry_text='%s'"
	        " serviceName='%s'"
	        " applicationName='%s'/>\n",
	        a->id, a->expiry, a->calendar,
	        a->key, buf, a->serviceName ? : "", a->applicationName ? : "");
}
Exemplo n.º 30
0
/*!
 * \brief Release memory allocated for the global web server root directory
 * and the global XML document. Resets the flag bWebServerState to
 * WEB_SERVER_DISABLED.
 *
 * \return Integer.
 */
static int get_file_info(
	/*! [in] Filename having the description document. */
	const char *filename,
	/*! [out] File information object having file attributes such as filelength,
	 * when was the file last modified, whether a file or a directory and
	 * whether the file or directory is readable. */
	struct File_Info *info)
{
	int code;
	struct osal_stat_t s;
	OSAL_FILE *fp;
	int rc = 0;
	struct tm date;
	char buffer[ASCTIME_R_BUFFER_SIZE];

	ixmlFreeDOMString(info->content_type);	
	info->content_type = NULL;
	code = osal_stat(filename, &s);
	if (code == -1)
		return -1;
	if (S_ISDIR(s.st_mode))
		info->is_directory = TRUE;
	else if (S_ISREG(s.st_mode))
		info->is_directory = FALSE;
	else
		return -1;
	if (info->is_directory == FALSE) {
		fp = osal_fopen(filename, "r");
		if (fp == NULL) return -1;
		osal_fclose(fp);
		/* check readable */
		info->is_readable = 1;
		info->file_length = s.st_size;
		info->last_modified = s.st_mtime;
		rc = get_content_type(filename, &info->content_type);
		UpnpPrintf(UPNP_INFO, HTTP, __FILE__, __LINE__,
			"file info: %s, length: %lld, last_mod=%s readable=%d\n",
			filename, (long long)info->file_length,
			asctime_r(http_gmtime_r(&info->last_modified, &date), buffer),
			info->is_readable);
	}
	return rc;
}