Added silc_fd_stream_file.
authorPekka Riikonen <priikone@silcnet.org>
Mon, 28 Nov 2005 17:18:31 +0000 (17:18 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Mon, 28 Nov 2005 17:18:31 +0000 (17:18 +0000)
CHANGES
lib/silcutil/silcfdstream.c
lib/silcutil/silcfdstream.h
lib/silcutil/silcfileutil.h
lib/silcutil/silcmutex.h

diff --git a/CHANGES b/CHANGES
index 54b60f2bbfed18dcd53c8ae40756406c8df96a3a..72b56db3422dc5ea5d2af2d26d52d214cafab64b 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -3,6 +3,8 @@ Mon Nov 28 17:06:54 EET 2005  Pekka Riikonen <priikone@silcnet.org>
        * Added silc_file_set_nonblock.  Affected file is
          lib/silcutil/silcfileutil.h.
 
+       * Added silc_fd_stream_file to lib/silcutil/silcfdstream.[ch].
+
 Sat Nov 26 16:13:40 EET 2005  Pekka Riikonen <priikone@silcnet.org>
 
        * FSM based implementation of SILC SKE.  Simpler interface also.
index c47aae8e393f0e93ef9f367dbe322c8c541e0fec..d707e59a326029d073e220b62a4f11dd1c8fd97c 100644 (file)
@@ -103,6 +103,31 @@ SilcStream silc_fd_stream_create2(int read_fd, int write_fd,
   return stream;
 }
 
+/* Create by opening file */
+
+SilcStream silc_fd_stream_file(const char *filename,
+                              SilcBool reading, SilcBool writing,
+                              SilcSchedule schedule)
+{
+  int fd, flags = 0;
+
+  if (!filename)
+    return NULL;
+
+  if (reading)
+    flags |= O_RDONLY;
+  if (writing)
+    flags |= O_WRONLY;
+  if (reading && writing)
+    flags |= O_RDWR;
+
+  fd = silc_file_open(filename, flags);
+  if (fd < 0)
+    return NULL;
+
+  return silc_fd_stream_create(fd, schedule);
+}
+
 /* Return fds */
 
 SilcBool silc_fd_stream_get_info(SilcStream stream, int *read_fd, int *write_fd)
index 9904fcac0dafcffe8290a8242084a0340fcb8ce8..fc1a4c8f243dd4fd529250d918cc4ee3f18213ef 100644 (file)
@@ -67,6 +67,24 @@ SilcStream silc_fd_stream_create(int fd, SilcSchedule schedule);
 SilcStream silc_fd_stream_create2(int read_fd, int write_fd,
                                  SilcSchedule schedule);
 
+/****f* silcutil/SilcFDStreamAPI/silc_fd_stream_file
+ *
+ * SYNOPSIS
+ *
+ *    SilcStream silc_fd_stream_file(const char *filename, SilcBool reading,
+ *                                   SilcBool writing, SilcSchedule schedule);
+ *
+ * DESCRIPTION
+ *
+ *    Same as silc_fd_stream_create but creates the stream by opening the
+ *    file indicated by `filename'.  If the `reading' is TRUE the file is
+ *    opened for reading.  If the `writing' is TRUE the file is opened
+ *    for writing.
+ *
+ ***/
+SilcStream silc_fd_stream_file(const char *filename, SilcBool reading, 
+                              SilcBool writing, SilcSchedule schedule);
+
 /****f* silcutil/SilcFDStreamAPI/silc_fd_stream_get_info
  *
  * SYNOPSIS
index 3437870aa36cc30e7bc1fe40d532f869cc46e661..80e9d99a45be468e4ec1a3942af1bf135b8e2797 100644 (file)
@@ -100,7 +100,7 @@ int silc_file_write(int fd, const char *buffer, SilcUInt32 len);
  ***/
 int silc_file_close(int fd);
 
-/****f* silcutil/SilcNetAPI/silc_file_set_nonblock
+/****f* silcutil/SilcFileUtilAPI/silc_file_set_nonblock
  *
  * SYNOPSIS
  *
index c92a23c53613bb56fcdfa194b36a0f408b11497f..52407855d648726701c08bda6cb032282fd3230d 100644 (file)
  ***/
 typedef struct SilcMutexStruct *SilcMutex;
 
-/****d* silcutil/SilcMutexAPI/SILC_MUTEX_DEFINE
- *
- * NAME
- *
- *    #define SILC_MUTEX_DEFINE(name) ...
- *
- * DESCRIPTION
- *
- *    This macro is used to define new mutex.  Use this macro in an
- *    environment that can be compiled with or without the SILC Mutex
- *    API. This is equivalent to defining SilcMutex `name'; directly.
- *
- * SOURCE
- */
-#define SILC_MUTEX_DEFINE(name) SilcMutex name
-/***/
-
 /****f* silcutil/SilcMutexAPI/silc_mutex_alloc
  *
  * SYNOPSIS