/* ql_sysconf.qpp Qore Programming Language Copyright 2012-2013 Qore Technologies This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include /** @mainpage %Qore %Sysconf Module Contents of this documentation: - @ref intro - @ref functions - @ref constants @section intro Introduction The sysconf module provides Qore the possibility to obtain runtime system infomation from the underlying operating system. The functionality is provided by standard C library. This module is released under the LGPL 2.1 and is tagged as such in the module's header (meaning it can be loaded unconditionally regardless of how the %Qore library was initialized). This version of the module requires Qore 0.8.0+ to compile and run. To use the module in a %Qore script, use the \c %%requires directive as follows: @code %requires sysconf @endcode Short example; @code %requires sysconf printf("Count of CPUs: %N\n", sysconf(Sysconf::SC_NPROCESSORS_ONLN)); @endcode @section functions Functions See @ref sysconf_functions @section constants Constants See: - @ref sysconf_constants - @ref pathconf_constants - @ref confstr_constants */ static QoreNamespace SysconfNS("Sysconf"); static QoreNamespace PathconfNS("Pathconf"); static QoreNamespace ConfstrNS("Confstr"); void init_sysconf_functions(QoreNamespace& ns); void init_confstr_constants(QoreNamespace& ns); void init_pathconf_constants(QoreNamespace& ns); void init_sysconf_constants(QoreNamespace& ns); QoreStringNode * sysconf_module_init() { init_sysconf_functions(SysconfNS); init_confstr_constants(ConfstrNS); init_pathconf_constants(PathconfNS); init_sysconf_constants(SysconfNS); return 0; } void sysconf_module_ns_init(QoreNamespace *rns, QoreNamespace *qns) { qns->addNamespace(SysconfNS.copy()); qns->addNamespace(ConfstrNS.copy()); qns->addNamespace(PathconfNS.copy()); } void sysconf_module_delete() { // nothing to do here in this case } // qore module symbols DLLEXPORT char qore_module_name[] = "sysconf"; DLLEXPORT char qore_module_version[] = PACKAGE_VERSION; DLLEXPORT char qore_module_description[] = "Sysconf library wrapper"; DLLEXPORT char qore_module_author[] = "Petr Vanek"; DLLEXPORT char qore_module_url[] = "http://qore.org"; DLLEXPORT int qore_module_api_major = QORE_MODULE_API_MAJOR; DLLEXPORT int qore_module_api_minor = QORE_MODULE_API_MINOR; DLLEXPORT qore_module_init_t qore_module_init = sysconf_module_init; DLLEXPORT qore_module_ns_init_t qore_module_ns_init = sysconf_module_ns_init; DLLEXPORT qore_module_delete_t qore_module_delete = sysconf_module_delete; DLLEXPORT qore_license_t qore_module_license = QL_LGPL; # 115 "/export/home/dnichols/src/el7/qore/git/module-sysconf/src/sysconf.qpp" # 120 "/export/home/dnichols/src/el7/qore/git/module-sysconf/src/sysconf.qpp" # 143 "/export/home/dnichols/src/el7/qore/git/module-sysconf/src/sysconf.qpp" # 153 "/export/home/dnichols/src/el7/qore/git/module-sysconf/src/sysconf.qpp" # 185 "/export/home/dnichols/src/el7/qore/git/module-sysconf/src/sysconf.qpp" # 194 "/export/home/dnichols/src/el7/qore/git/module-sysconf/src/sysconf.qpp" // TODO/FIXME: File is not public? /* */ //int fpathconf(ReadonlyFile[File] file, int param) { //#ifdef HAVE_PATHCONF // errno = 0; // int ret = fpathconf(file->getFD(), param); // // if (errno != 0) { // xsink->raiseErrnoException("FPATHCONF-ERROR", errno, "fpathconf(%d) failed", param); // return 0; // } // // //return new QoreBigIntNode(ret); // return ret; //#else // return missing_function_error("fpathconf", xsink); //#endif //} # 238 "/export/home/dnichols/src/el7/qore/git/module-sysconf/src/sysconf.qpp" // string confstr(int param) {} static AbstractQoreNode* f_confstr_Vi(const QoreListNode* args, ExceptionSink* xsink) { int64 param = HARD_QORE_INT(args, 0); # 159 "/export/home/dnichols/src/el7/qore/git/module-sysconf/src/sysconf.qpp" #ifdef HAVE_CONFSTR size_t len = confstr (param, NULL, 0); if (!len || errno != 0) { xsink->raiseErrnoException("CONFSTR-ERROR", errno, "confstr(%d) failed", param); return 0; } SimpleRefHolder rv(new QoreStringNode); // this reserves len + 1 bytes in the string rv->reserve(len); // theoretically there should be no error here, but just in case we have additional error handling errno = 0; if (!confstr(param, (char*)rv->getBuffer(), len + 1) || errno) { xsink->raiseErrnoException("CONFSTR-ERROR", errno, "confstr(%d) failed", param); return 0; } rv->terminate(len); return rv.release(); #else return missing_function_error("confstr", xsink); #endif return 0; } // hash confstr_constants() {} static AbstractQoreNode* f_confstr_constants(const QoreListNode* args, ExceptionSink* xsink) { # 190 "/export/home/dnichols/src/el7/qore/git/module-sysconf/src/sysconf.qpp" return ConfstrNS.getConstantInfo(); } // int pathconf(string filename, int param) {} static int64 f_pathconf_VsVi(const QoreListNode* args, ExceptionSink* xsink) { const QoreStringNode* filename = HARD_QORE_STRING(args, 0); int64 param = HARD_QORE_INT(args, 1); # 201 "/export/home/dnichols/src/el7/qore/git/module-sysconf/src/sysconf.qpp" #ifdef HAVE_PATHCONF errno = 0; int ret = pathconf(filename->getBuffer(), param); if (errno != 0) { xsink->raiseErrnoException("PATHCONF-ERROR", errno, "pathconf(%d) failed", param); return 0; } //return new QoreBigIntNode(ret); return ret; #else return missing_function_error("pathconf", xsink); #endif return 0; } // hash pathconf_constants() {} static AbstractQoreNode* f_pathconf_constants(const QoreListNode* args, ExceptionSink* xsink) { # 243 "/export/home/dnichols/src/el7/qore/git/module-sysconf/src/sysconf.qpp" return PathconfNS.getConstantInfo(); } // int sysconf(int param) {} static int64 f_sysconf_Vi(const QoreListNode* args, ExceptionSink* xsink) { int64 param = HARD_QORE_INT(args, 0); # 126 "/export/home/dnichols/src/el7/qore/git/module-sysconf/src/sysconf.qpp" #ifdef HAVE_SYSCONF errno = 0; int ret = sysconf(param); if (errno != 0) { xsink->raiseErrnoException("SYSCONF-ERROR", errno, "sysconf(%d) failed", param); return 0; } //return new QoreBigIntNode(ret); return ret; #else return missing_function_error("sysconf", xsink); #endif return 0; } // hash sysconf_constants() {} static AbstractQoreNode* f_sysconf_constants(const QoreListNode* args, ExceptionSink* xsink) { # 148 "/export/home/dnichols/src/el7/qore/git/module-sysconf/src/sysconf.qpp" return SysconfNS.getConstantInfo(); } DLLLOCAL void init_sysconf_functions(QoreNamespace& ns) { // string confstr(int param) {} ns.addBuiltinVariant("confstr", (q_func_t)f_confstr_Vi, QC_RET_VALUE_ONLY, QDOM_DEFAULT, stringTypeInfo, 1, bigIntTypeInfo, NULL, "param"); // hash confstr_constants() {} ns.addBuiltinVariant("confstr_constants", (q_func_t)f_confstr_constants, QC_CONSTANT, QDOM_DEFAULT, hashTypeInfo); // int pathconf(string filename, int param) {} ns.addBuiltinVariant("pathconf", (q_func_int64_t)f_pathconf_VsVi, QC_RET_VALUE_ONLY, QDOM_DEFAULT, bigIntTypeInfo, 2, stringTypeInfo, NULL, "filename", bigIntTypeInfo, NULL, "param"); // hash pathconf_constants() {} ns.addBuiltinVariant("pathconf_constants", (q_func_t)f_pathconf_constants, QC_CONSTANT, QDOM_DEFAULT, hashTypeInfo); // int sysconf(int param) {} ns.addBuiltinVariant("sysconf", (q_func_int64_t)f_sysconf_Vi, QC_RET_VALUE_ONLY, QDOM_DEFAULT, bigIntTypeInfo, 1, bigIntTypeInfo, NULL, "param"); // hash sysconf_constants() {} ns.addBuiltinVariant("sysconf_constants", (q_func_t)f_sysconf_constants, QC_CONSTANT, QDOM_DEFAULT, hashTypeInfo); }