Fixed %p formatting in silc_snprintf.
authorPekka Riikonen <priikone@silcnet.org>
Wed, 3 Jan 2007 16:52:34 +0000 (16:52 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Wed, 3 Jan 2007 16:52:34 +0000 (16:52 +0000)
Fixed FD task addition to scheduler; schedule task immediately
when adding it with initial SILC_TASK_READ.

lib/silcutil/DIRECTORY
lib/silcutil/silcschedule.c
lib/silcutil/silcsnprintf.c
lib/silcutil/silcsnprintf.h
lib/silcutil/unix/silcunixschedule.c

index 2b334d5e3a63a489de405a79962adf9ce6eedb48..2a566a74706060e511ba8aaaf14fe1000abfc022 100644 (file)
@@ -19,6 +19,7 @@
 @LINK=silcfsm.html:Finite State Machine Interface
 @LINK=silcfileutil.html:File Utility Functions
 @LINK=silcstrutil.html:String Utility Interface
+@LINK=silcsnprintf.html:Snprintf Interface
 @LINK=silcutf8.html:UTF-8 String Interface
 @LINK=silcstringprep.html:Stringprep Interface
 @LINK=silcutil.html:Utility Functions
index c0ee5dea72e3c9d6e080ca4df0e38b175a95c17e..aa648e3908eb5bb58be946ef27ae4d846fddf1ff 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1998 - 2006 Pekka Riikonen
+  Copyright (C) 1998 - 2007 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -624,8 +624,10 @@ SilcTask silc_schedule_task_add(SilcSchedule schedule, SilcUInt32 fd,
     ftask->events = SILC_TASK_READ;
     ftask->fd = fd;
 
-    /* Add task */
+    /* Add task and schedule it */
     silc_hash_table_add(schedule->fd_queue, SILC_32_TO_PTR(fd), ftask);
+    schedule_ops.schedule_fd(schedule, schedule->internal, ftask,
+                            ftask->events);
 
     task = (SilcTask)ftask;
 
index 633bdf1d295eb489d6a477c165ccc86aa7a7705d..501625abf21704d2fde80b45c65947fe00f2f165 100644 (file)
@@ -91,6 +91,7 @@
 #define DP_F_ZERO      (1 << 4)
 #define DP_F_UP        (1 << 5)
 #define DP_F_UNSIGNED  (1 << 6)
+#define DP_F_HEXPREFIX         (1 << 7)
 
 /* Conversion Flags */
 #define DP_C_SHORT   1
@@ -322,8 +323,10 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format,
        fmtstr (buffer, &currlen, maxlen, strvalue, flags, min, max);
        break;
       case 'p':
+       flags |= (DP_F_UNSIGNED | DP_F_HEXPREFIX);
        strvalue = va_arg (args, void *);
-       fmtint (buffer, &currlen, maxlen, (long) strvalue, 16, min, max, flags);
+       fmtint (buffer, &currlen, maxlen, (long )strvalue, 16, min, max,
+               flags);
        break;
       case 'n':
        if (cflags == DP_C_SHORT) {
@@ -413,7 +416,7 @@ static void fmtstr(char *buffer, size_t *currlen, size_t maxlen,
 /* Have to handle DP_F_NUM (ie 0x and 0 alternates) */
 
 static void fmtint(char *buffer, size_t *currlen, size_t maxlen,
-                   long value, int base, int min, int max, int flags)
+                  long value, int base, int min, int max, int flags)
 {
   int signvalue = 0;
   unsigned long uvalue;
@@ -468,6 +471,12 @@ static void fmtint(char *buffer, size_t *currlen, size_t maxlen,
     --spadlen;
   }
 
+  /* 0x prefix */
+  if (flags & DP_F_HEXPREFIX) {
+    dopr_outch (buffer, currlen, maxlen, '0');
+    dopr_outch (buffer, currlen, maxlen, 'x');
+  }
+
   /* Sign */
   if (signvalue)
     dopr_outch (buffer, currlen, maxlen, signvalue);
index d15b1c9ff7deed36e45cb09a0584b4fad17bc3b8..00ae8c2c502c155ee70641beb7dded9ed26257cc 100644 (file)
 
 */
 
+/****h* silcutil/Snprintf
+ *
+ * DESCRIPTION
+ *
+ * Platform independent version of snprintf and other similar string
+ * formatting routines.
+ *
+ ***/
+
 #ifndef SILCSNPRINTF_H
 #define SILCSNPRINTF_H
 
index d169ee5222c12b77d3881e293f797d2838ed2a48..ecddd88e28620745f6575e4a02cf27c9463b4ccb 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1998 - 2006 Pekka Riikonen
+  Copyright (C) 1998 - 2007 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -266,6 +266,9 @@ SilcBool silc_schedule_internal_schedule_fd(SilcSchedule schedule,
   SilcUnixScheduler internal = (SilcUnixScheduler)context;
   struct epoll_event event;
 
+  if (!internal)
+    return FALSE;
+
   event.events = 0;
   if (task->events & SILC_TASK_READ)
     event.events |= (EPOLLIN | EPOLLPRI);
@@ -372,6 +375,9 @@ void *silc_schedule_internal_init(SilcSchedule schedule,
     return NULL;
   }
 #endif
+  silc_schedule_internal_schedule_fd(schedule, internal,
+                                    (SilcTaskFd)internal->wakeup_task,
+                                    SILC_TASK_READ);
 
   internal->app_context = app_context;