Back to index

lightning-sunbird  0.9+nobinonly
io.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org code, released
00017  * Jan 28, 2003.
00018  *
00019  * The Initial Developer of the Original Code is
00020  * Netscape Communications Corporation.
00021  * Portions created by the Initial Developer are Copyright (C) 2003
00022  * the Initial Developer. All Rights Reserved.
00023  *
00024  * Contributor(s):
00025  *   Garrett Arch Blythe, 28-January-2003
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either the GNU General Public License Version 2 or later (the "GPL"), or
00029  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 #include "mozce_internal.h"
00042 
00043 extern "C" {
00044 #if 0
00045 }
00046 #endif
00047 
00048 
00049 MOZCE_SHUNT_API int mozce_chmod(const char* inFilename, int inMode)
00050 {
00051     MOZCE_PRECHECK
00052 
00053 #ifdef DEBUG
00054     mozce_printf("mozce_chmod called\n");
00055 #endif
00056     
00057     int retval = -1;
00058     
00059     if(NULL != inFilename)
00060     {
00061         unsigned short buffer[MAX_PATH];
00062         
00063         int convRes = a2w_buffer(inFilename, -1, buffer, sizeof(buffer) / sizeof(unsigned short));
00064         if(0 != convRes)
00065         {
00066             DWORD attribs = 0;
00067             
00068             attribs = GetFileAttributesW(buffer);
00069             if(0 != attribs)
00070             {
00071                 if(0 != (_S_IWRITE & inMode))
00072                 {
00073                     attribs |= FILE_ATTRIBUTE_READONLY;
00074                 }
00075                 else
00076                 {
00077                     attribs &= ~FILE_ATTRIBUTE_READONLY;
00078                 }
00079                 
00080                 BOOL setRes = SetFileAttributesW(buffer, attribs);
00081                 if(FALSE != setRes)
00082                 {
00083                     retval = 0;
00084                 }
00085             }
00086         }
00087     }
00088     
00089     return retval;
00090 }
00091 
00092 
00093 MOZCE_SHUNT_API int mozce_isatty(int inHandle)
00094 {
00095     MOZCE_PRECHECK
00096 
00097 #ifdef DEBUG
00098     mozce_printf("-- mozce_isatty called\n");
00099 #endif
00100     
00101     int retval = 0;
00102     
00103     return retval;
00104 }
00105 
00106 
00107 
00108 /*
00109  * Our static protocols entries.
00110  */
00111 static struct protoent sProtos[] = {
00112     { "tcp",    NULL,   IPPROTO_TCP },
00113     { "udp",    NULL,   IPPROTO_UDP },
00114     { "ip",     NULL,   IPPROTO_IP },
00115     { "icmp",   NULL,   IPPROTO_ICMP },
00116     { "ggp",    NULL,   IPPROTO_GGP },
00117     { "pup",    NULL,   IPPROTO_PUP },
00118     { "idp",    NULL,   IPPROTO_IDP },
00119     { "nd",     NULL,   IPPROTO_ND },
00120     { "raw",    NULL,   IPPROTO_RAW }
00121 };
00122 
00123 #define MAX_PROTOS (sizeof(sProtos) / sizeof(struct protoent))
00124 
00125 /*
00126  * Wingetprotobyname
00127  *
00128  * As getprotobyname
00129  */
00130 MOZCE_SHUNT_API struct protoent* mozce_getprotobyname(const char* inName)
00131 {
00132     struct protoent* retval = NULL;
00133 
00134     if(NULL != inName)
00135     {
00136         unsigned uLoop;
00137 
00138         for(uLoop = 0; uLoop < MAX_PROTOS; uLoop++)
00139         {
00140             if(0 == _stricmp(inName, sProtos[uLoop].p_name))
00141             {
00142                 retval = &sProtos[uLoop];
00143                 break;
00144             }
00145         }
00146     }
00147 
00148     return retval;
00149 }
00150 
00151 /*
00152  * Wingetprotobynumber
00153  *
00154  * As getprotobynumber
00155  */
00156 MOZCE_SHUNT_API struct protoent* mozce_getprotobynumber(int inNumber)
00157 {
00158     struct protoent* retval = NULL;
00159     unsigned uLoop;
00160     
00161     for(uLoop = 0; uLoop < MAX_PROTOS; uLoop++)
00162     {
00163         if(inNumber == sProtos[uLoop].p_proto)
00164         {
00165             retval = &sProtos[uLoop];
00166             break;
00167         }
00168     }
00169 
00170     return retval;
00171 
00172 }
00173 #if 0
00174 {
00175 #endif
00176 } /* extern "C" */
00177