Exemple #1
0
static void *file_stdio_fopen(const char *path, const char *mode)
{
   FILE *fp;
   USERDATA *userdata;

   ALLEGRO_DEBUG("opening %s %s\n", path, mode);

#ifdef ALLEGRO_WINDOWS
   {
      wchar_t *wpath = _al_win_utf16(path);
      wchar_t *wmode = _al_win_utf16(mode);
      fp = _wfopen(wpath, wmode);
      al_free(wpath);
      al_free(wmode);
   }
#else
   fp = fopen(path, mode);
#endif

   if (!fp) {
      al_set_errno(errno);
      return NULL;
   }

   userdata = al_malloc(sizeof(USERDATA));
   if (!userdata) {
      fclose(fp);
      return NULL;
   }

   userdata->fp = fp;
   userdata->errnum = 0;

   return userdata;
}
Exemple #2
0
static void *file_stdio_fopen(const char *path, const char *mode)
{
   FILE *fp;

#ifdef ALLEGRO_WINDOWS
   {
      wchar_t *wpath = _al_win_utf16(path);
      wchar_t *wmode = _al_win_utf16(mode);
      fp = _wfopen(wpath, wmode);
      al_free(wpath);
      al_free(wmode);
   }
#else
   fp = fopen(path, mode);
#endif

   if (!fp) {
      al_set_errno(errno);
      return NULL;
   }

   return fp;
}
Exemple #3
0
static bool win_set_clipboard_text(ALLEGRO_DISPLAY *display, const char *text)
{
   HWND handle = get_window_handle(display);
   HANDLE hMem = NULL;
   wchar_t *tstr = NULL;
   size_t size;
   size_t len;
   LPTSTR dst;

   if (!OpenClipboard(handle)) {
      ALLEGRO_DEBUG("Could not open clipboard for handle %p", handle);
      return false;
   }

   /* Convert the text from UTF-8 to Windows Unicode */
   tstr = _al_win_utf16(text);
   len  = wcslen(tstr);
   size = (len+1) * sizeof(wchar_t);
   /* Save the data to the clipboard */
   hMem = GlobalAlloc(GMEM_MOVEABLE, size);

   if (!hMem) {
      al_free(tstr);
      ALLEGRO_DEBUG("GlobalAlloc failed to allocate memory for the clipboard data");
      return false;
   }

   dst = (LPTSTR)GlobalLock(hMem);
   /* Copy the text over. Unlike SDL, do NOT convert newlines, that's for the
    * use to decide. */
   memmove(dst, tstr, size);
   dst[len] = 0;
   GlobalUnlock(hMem);
   EmptyClipboard();
   if (!SetClipboardData(TEXT_FORMAT, hMem)) {
      al_free(tstr);
      ALLEGRO_DEBUG("Couldn't set clipboard data");
      return false;
   }
   al_free(tstr);
   CloseClipboard();
   return true;
}