Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: src/platform-posix.cc

Issue 45063: Moved stdio and string functions to POSIX platform file (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/platform-macos.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 double OS::LocalTimeOffset() { 98 double OS::LocalTimeOffset() {
99 time_t tv = time(NULL); 99 time_t tv = time(NULL);
100 struct tm* t = localtime(&tv); 100 struct tm* t = localtime(&tv);
101 // tm_gmtoff includes any daylight savings offset, so subtract it. 101 // tm_gmtoff includes any daylight savings offset, so subtract it.
102 return static_cast<double>(t->tm_gmtoff * msPerSecond - 102 return static_cast<double>(t->tm_gmtoff * msPerSecond -
103 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0)); 103 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0));
104 } 104 }
105 105
106 106
107 // ---------------------------------------------------------------------------- 107 // ----------------------------------------------------------------------------
108 // POSIX stdio support.
109 //
110
111 FILE* OS::FOpen(const char* path, const char* mode) {
112 return fopen(path, mode);
113 }
114
115
116 void OS::Print(const char* format, ...) {
117 va_list args;
118 va_start(args, format);
119 VPrint(format, args);
120 va_end(args);
121 }
122
123
124 void OS::VPrint(const char* format, va_list args) {
125 vprintf(format, args);
126 }
127
128
129 void OS::PrintError(const char* format, ...) {
130 va_list args;
131 va_start(args, format);
132 VPrintError(format, args);
133 va_end(args);
134 }
135
136
137 void OS::VPrintError(const char* format, va_list args) {
138 vfprintf(stderr, format, args);
139 }
140
141
142 int OS::SNPrintF(Vector<char> str, const char* format, ...) {
143 va_list args;
144 va_start(args, format);
145 int result = VSNPrintF(str, format, args);
146 va_end(args);
147 return result;
148 }
149
150
151 int OS::VSNPrintF(Vector<char> str,
152 const char* format,
153 va_list args) {
154 int n = vsnprintf(str.start(), str.length(), format, args);
155 if (n < 0 || n >= str.length()) {
156 str[str.length() - 1] = '\0';
157 return -1;
158 } else {
159 return n;
160 }
161 }
162
163
164 // ----------------------------------------------------------------------------
165 // POSIX string support.
166 //
167
168 char* OS::StrChr(char* str, int c) {
169 return strchr(str, c);
170 }
171
172
173 void OS::StrNCpy(Vector<char> dest, const char* src, size_t n) {
174 strncpy(dest.start(), src, n);
175 }
176
177
178 // ----------------------------------------------------------------------------
108 // POSIX socket support. 179 // POSIX socket support.
109 // 180 //
110 181
111 class POSIXSocket : public Socket { 182 class POSIXSocket : public Socket {
112 public: 183 public:
113 explicit POSIXSocket() { 184 explicit POSIXSocket() {
114 // Create the socket. 185 // Create the socket.
115 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 186 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
116 } 187 }
117 explicit POSIXSocket(int socket): socket_(socket) { } 188 explicit POSIXSocket(int socket): socket_(socket) { }
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 return ntohl(value); 338 return ntohl(value);
268 } 339 }
269 340
270 341
271 Socket* OS::CreateSocket() { 342 Socket* OS::CreateSocket() {
272 return new POSIXSocket(); 343 return new POSIXSocket();
273 } 344 }
274 345
275 346
276 } } // namespace v8::internal 347 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-macos.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698