Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1207)

Unified Diff: src/process-manager/simu-stdio.cc

Issue 82064: add several system call emulation support for ns-3-simu (Closed)
Patch Set: Created 14 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/process-manager/simu-stdio.h ('k') | src/process-manager/simu-unistd.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
+}
« no previous file with comments | « src/process-manager/simu-stdio.h ('k') | src/process-manager/simu-unistd.h » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b