ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

mwerks_console_OS_X.c
Go to the documentation of this file.
00001 /* Metrowerks Standard Library
00002  * Copyright © 1995-2002 Metrowerks Corporation.  All rights reserved.
00003  *
00004  * $Date$
00005  * $Revision$
00006  */
00007 
00008 #include <ansi_parms.h>
00009 #include <size_t.h>
00010 #include <console.h>
00011 #include <unistd.h>
00012 
00013 #if __MACH__
00014   short InstallConsole(short fd)
00015   {
00016   #pragma unused (fd)
00017 
00018     return 0;
00019   }
00020 #else
00021   #include <Carbon.h>
00022 
00023   typedef int (*ReadPtr)(int, void *, __std(size_t));
00024   typedef int (*WritePtr)(int, const void *, __std(size_t));
00025 
00026   static struct
00027   {
00028     Boolean isLoaded;
00029     CFBundleRef theBundle;
00030     ReadPtr theRead;
00031     WritePtr theWrite;
00032   } __msl_os_x;
00033 
00034   static OSErr __msl_CreateFrameworkBundleFromName(CFStringRef theFrameworkName,
00035     CFBundleRef *theBundle)
00036   {
00037     OSErr theErr;
00038     FSRef theRef;
00039     CFURLRef theFrameworkURL;
00040     CFURLRef theBundleURL;
00041 
00042     /* Find the folder containing all the frameworks */
00043     theErr = FSFindFolder(kOnAppropriateDisk, kFrameworksFolderType, false, &theRef);
00044 
00045     if (theErr == noErr)
00046     {
00047       /* Turn the framework folder FSRef into a CFURL */
00048       theFrameworkURL = CFURLCreateFromFSRef(kCFAllocatorSystemDefault, &theRef);
00049 
00050       if (theFrameworkURL != NULL)
00051       {
00052         /* Create a CFURL pointing to the desired framework */
00053         theBundleURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault,
00054           theFrameworkURL, theFrameworkName, false);
00055 
00056         CFRelease(theFrameworkURL);
00057 
00058         if (theBundleURL != NULL)
00059         {
00060           /* Turn the CFURL into a bundle reference */
00061           *theBundle = CFBundleCreate(kCFAllocatorSystemDefault, theBundleURL);
00062 
00063           CFRelease(theBundleURL);
00064         }
00065       }
00066     }
00067 
00068     return theErr;
00069   }
00070 
00071   short InstallConsole(short fd)
00072   {
00073   #pragma unused (fd)
00074     OSErr theErr;
00075     short theResult;
00076 
00077     theResult = -1;
00078 
00079     /* Start with no bundle */
00080     __msl_os_x.isLoaded = false;
00081     __msl_os_x.theBundle = NULL;
00082     __msl_os_x.theRead = NULL;
00083     __msl_os_x.theWrite = NULL;
00084 
00085     /* Create a bundle reference based on its name */
00086     theErr = __msl_CreateFrameworkBundleFromName(CFSTR("System.framework"),
00087       &__msl_os_x.theBundle);
00088 
00089     if ((theErr == noErr) && (__msl_os_x.theBundle != NULL))
00090     {
00091       theResult = 0;
00092 
00093       __msl_os_x.isLoaded = CFBundleLoadExecutable(__msl_os_x.theBundle);
00094 
00095       if (__msl_os_x.isLoaded)
00096       {
00097         /* Lookup the functions in the bundle by name */
00098         __msl_os_x.theRead = (ReadPtr)
00099           CFBundleGetFunctionPointerForName(__msl_os_x.theBundle, CFSTR("read"));
00100         __msl_os_x.theWrite = (WritePtr)
00101           CFBundleGetFunctionPointerForName(__msl_os_x.theBundle, CFSTR("write"));
00102       }
00103     }
00104 
00105     return theResult;
00106   }
00107 #endif
00108 
00109 void RemoveConsole(void)
00110 {
00111 #if !__MACH__
00112   if (__msl_os_x.theBundle != NULL)
00113   {
00114     if (__msl_os_x.isLoaded)
00115     {
00116       __msl_os_x.theRead = NULL;
00117       __msl_os_x.theWrite = NULL;
00118 
00119       CFBundleUnloadExecutable(__msl_os_x.theBundle);
00120       __msl_os_x.isLoaded = false;
00121     }
00122 
00123     CFRelease(__msl_os_x.theBundle);
00124     __msl_os_x.theBundle = NULL;
00125   }
00126 #endif
00127 }
00128 
00129 long WriteCharsToConsole(char *buffer, long n)
00130 {
00131 #if __MACH__
00132   return write(1, buffer, n);
00133 #else
00134   /* Call the function if it was found */
00135   if (__msl_os_x.theWrite == NULL)
00136     return -1;
00137   else
00138     return __msl_os_x.theWrite(1, buffer, n);
00139 #endif
00140 }
00141 
00142 #if __MACH__
00143 long WriteCharsToErrorConsole(char *buffer, long n)
00144 {
00145   return write(2, buffer, n);
00146 }
00147 #endif
00148 
00149 long ReadCharsFromConsole(char *buffer, long n)
00150 {
00151 #if __MACH__
00152   return read(0, buffer, n);
00153 #else
00154   /* Call the function if it was found */
00155   if (__msl_os_x.theRead == NULL)
00156     return -1;
00157   else
00158     return __msl_os_x.theRead(0, buffer, n);
00159 #endif
00160 }
00161 
00162 /* JWW - This code should never be reached, but it's needed for link purposes */
00163 char *__ttyname(long fildes)
00164 {
00165 #pragma unused (fildes)
00166   /* all streams have the same name */
00167   static char *__devicename = "Terminal";
00168 
00169   if (fildes >= 0 && fildes <= 2)
00170     return (__devicename);
00171 
00172   return (0L);
00173 }
00174 
00175 int kbhit(void)
00176 {
00177   return 0;
00178 }
00179 
00180 int getch(void)
00181 {
00182   return 0;
00183 }
00184 
00185 void clrscr()
00186 {
00187   return;
00188 }
00189 
00190 /* Change record:
00191  * JWW 010919 Created Mach-O console stubs file
00192  * JWW 020418 Use __std() for all size_t, and #include <size_t.h> to get proper C++ definitions
00193  */

Generated on Sat May 26 2012 04:34:04 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.