Use folly::dynamic::object and folly::dynamic::string exclusivly
[hiphop-php.git] / hphp / runtime / base / user-stream-wrapper.cpp
blobee7f13cf99c91360c30e44b5c0ec978801d21125
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2014 Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/runtime/base/user-stream-wrapper.h"
18 #include "hphp/system/constants.h"
20 namespace HPHP {
21 ///////////////////////////////////////////////////////////////////////////////
23 UserStreamWrapper::UserStreamWrapper(const String& name,
24 const String& clsname,
25 int flags)
26 : m_name(name) {
27 m_cls = Unit::loadClass(clsname.get());
28 if (!m_cls) {
29 throw InvalidArgumentException(0, "Undefined class '%s'", clsname.data());
31 m_isLocal = !(flags & k_STREAM_IS_URL);
34 File* UserStreamWrapper::open(const String& filename, const String& mode,
35 int options, CVarRef context) {
36 auto file = NEWOBJ(UserFile)(m_cls, context);
37 Resource wrapper(file);
38 auto ret = file->openImpl(filename, mode, options);
39 if (!ret) {
40 return nullptr;
42 DEBUG_ONLY auto tmp = wrapper.detach();
43 assert(tmp == file && file->getCount() == 1);
44 file->decRefCount();
45 return file;
48 int UserStreamWrapper::access(const String& path, int mode) {
49 auto file = NEWOBJ(UserFile)(m_cls);
50 Resource wrapper(file);
51 return file->access(path, mode);
53 int UserStreamWrapper::lstat(const String& path, struct stat* buf) {
54 auto file = NEWOBJ(UserFile)(m_cls);
55 Resource wrapper(file);
56 return file->lstat(path, buf);
58 int UserStreamWrapper::stat(const String& path, struct stat* buf) {
59 auto file = NEWOBJ(UserFile)(m_cls);
60 Resource wrapper(file);
61 return file->stat(path, buf);
63 int UserStreamWrapper::unlink(const String& path) {
64 auto file = NEWOBJ(UserFile)(m_cls);
65 Resource wrapper(file);
66 return file->unlink(path) ? 0 : -1;
68 int UserStreamWrapper::rename(const String& oldname, const String& newname) {
69 auto file = NEWOBJ(UserFile)(m_cls);
70 Resource wrapper(file);
71 return file->rename(oldname, newname) ? 0 : -1;
73 int UserStreamWrapper::mkdir(const String& path, int mode, int options) {
74 auto file = NEWOBJ(UserFile)(m_cls);
75 Resource wrapper(file);
76 return file->mkdir(path, mode, options) ? 0 : -1;
78 int UserStreamWrapper::rmdir(const String& path, int options) {
79 auto file = NEWOBJ(UserFile)(m_cls);
80 Resource wrapper(file);
81 return file->rmdir(path, options) ? 0 : -1;
84 Directory* UserStreamWrapper::opendir(const String& path) {
85 auto dir = NEWOBJ(UserDirectory)(m_cls);
86 Resource wrapper(dir);
87 auto ret = dir->open(path);
88 if (!ret) {
89 return nullptr;
91 DEBUG_ONLY auto tmp = wrapper.detach();
92 assert(tmp == dir);
93 return dir;
96 ///////////////////////////////////////////////////////////////////////////////