Index: src/process-manager/simu-stdio.cc |
=================================================================== |
--- a/src/process-manager/simu-stdio.cc |
+++ b/src/process-manager/simu-stdio.cc |
@@ -298,7 +298,10 @@ |
NS_ASSERT (Current () != 0); |
Thread *current = Current (); |
char *str; |
- int retval = ::vasprintf (&str, format, ap); |
+ std::stringstream ss; |
+ ss << "Node" << UtilsGetNodeId() << ": " << format; |
+ |
+ int retval = ::vasprintf (&str, ss.str().c_str(), ap); |
if (retval == -1) |
{ |
current->err = errno; |
@@ -407,6 +410,38 @@ |
} |
return off; |
} |
+void simu_setbuf(FILE *stream, char *buf) |
+{ |
+ NS_LOG_FUNCTION (Current () << UtilsGetNodeId () << stream << buf); |
+ NS_ASSERT (Current () != 0); |
+ Thread *current = Current (); |
+ |
+ int index = SearchOpenStream (stream); |
+ if (index == -1) |
+ { |
+ current->err = EBADF; |
+ return; |
+ } |
+ |
+ // NOP FIXME |
+ return; |
+} |
+void simu_setbuffer(FILE *stream, char *buf, size_t size) |
+{ |
+ NS_LOG_FUNCTION (Current () << UtilsGetNodeId () << stream << buf); |
+ NS_ASSERT (Current () != 0); |
+ Thread *current = Current (); |
+ |
+ int index = SearchOpenStream (stream); |
+ if (index == -1) |
+ { |
+ current->err = EBADF; |
+ return; |
+ } |
+ |
+ // NOP FIXME |
+ return; |
+} |
void simu_rewind(FILE *stream) |
{ |
NS_LOG_FUNCTION (Current () << UtilsGetNodeId () << stream); |
@@ -414,3 +449,58 @@ |
simu_fseek (stream, 0, SEEK_SET); |
simu_clearerr (stream); |
} |
+int simu_fgetc(FILE *stream) |
+{ |
+ NS_LOG_FUNCTION (Current () << UtilsGetNodeId () << stream); |
+ NS_ASSERT (Current () != 0); |
+ Thread *current = Current (); |
+ int ptr; |
+ |
+ int index = SearchOpenStream (stream); |
+ if (index == -1) |
+ { |
+ current->err = EBADF; |
+ return EOF; |
+ } |
+ |
+ ssize_t data_read = simu_read (current->process->openStreams[index].fd, |
+ &ptr, sizeof(char)); |
+ if (data_read == 0) |
+ { |
+ current->process->openStreams[index].flags |= FILE_STREAM_EOF; |
+ return EOF; |
+ } |
+ else if (data_read == -1) |
+ { |
+ current->process->openStreams[index].flags |= FILE_STREAM_ERROR; |
+ return -1; |
+ } |
+ return ptr; |
+} |
+char* simu_fgets(char *s, int size, FILE *stream) |
+{ |
+ NS_LOG_FUNCTION (Current () << UtilsGetNodeId () << s << size << stream); |
+ NS_ASSERT (Current () != 0); |
+ Thread *current = Current (); |
+ |
+ register char *p; |
+ char c; |
+ |
+ if (s == 0) |
+ { |
+ current->err = EINVAL; |
+ return NULL; |
+ } |
+ |
+ p = s; |
+ while ((size > 1) && ((c = simu_fgetc (stream)) != EOF) && ((*p++ = c) != '\n')) |
+ { |
+ --size; |
+ } |
+ if (p == s) |
+ { |
+ return NULL; |
+ } |
+ *p = 0; |
+ return s; |
+} |