コード例 #1
1
ファイル: SDL_windows_main.c プロジェクト: boyxuper/kivy-ios
/* This is where execution begins [windowed apps] */
int WINAPI
WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPTSTR szCmdLine, int sw)
{
    char **argv;
    int argc;
    char *cmdline;
    char *bufp;
    size_t nLen;

    /* Grab the command line */
    bufp = GetCommandLine();
    nLen = SDL_strlen(bufp) + 1;
    cmdline = SDL_stack_alloc(char, nLen);
    if (cmdline == NULL) {
        return OutOfMemory();
    }
    SDL_strlcpy(cmdline, bufp, nLen);

    /* Parse it into argv and argc */
    argc = ParseCommandLine(cmdline, NULL);
    argv = SDL_stack_alloc(char *, argc + 1);
    if (argv == NULL) {
        return OutOfMemory();
    }
    ParseCommandLine(cmdline, argv);

    /* Run the main program */
    console_main(argc, argv);

    /* Hush little compiler, don't you cry... */
    return 0;
}
コード例 #2
0
ファイル: Entities.cpp プロジェクト: barba-anto/PC-Game4D1
Entities::Entities(int grandezza,bool solido,SDL_Texture* texture,SDL_Renderer* renderizzatore,SDL_Rect* tile, int frame, char* tipo,char* contenuto) {
	Entities::dimensione = grandezza;
	Entities::texture = texture;
	Entities::renderizzatore = renderizzatore;
	Entities::tile = tile;
	Entities::solido = solido;
	Entities::frame = frame;
	Entities::frame_attuale = 0;
	Entities::tipo = (char*)SDL_malloc(SDL_strlen(tipo));
	SDL_strlcpy(Entities::tipo,tipo,sizeof(char)*(SDL_strlen(tipo)+1));
	Entities::contenuto = (char*)SDL_malloc(SDL_strlen(contenuto));
	SDL_strlcpy(Entities::contenuto,contenuto,sizeof(char*)*(SDL_strlen(contenuto)+1));
}
コード例 #3
0
ファイル: global.c プロジェクト: cbhuber/Games
char * string_cat(const char * s1, const char * s2) {
	int len = SDL_strlen(s1) + SDL_strlen(s2) + 1;
	char * buf = malloc(len);
	SDL_strlcpy(buf, s1, len);
	SDL_strlcat(buf, s2, len);
	return buf;
}
コード例 #4
0
ファイル: SDL_getenv.c プロジェクト: ahpho/wowmapviewer
/* Put a variable of the form "name=value" into the environment */
int SDL_putenv(const char *variable)
{
	size_t bufferlen;
	char *value;
	const char *sep;

	sep = SDL_strchr(variable, '=');
	if ( sep == NULL ) {
		return -1;
	}
	bufferlen = SDL_strlen(variable)+1;
	if ( bufferlen > SDL_envmemlen ) {
		char *newmem = (char *)SDL_realloc(SDL_envmem, bufferlen);
		if ( newmem == NULL ) {
			return -1;
		}
		SDL_envmem = newmem;
		SDL_envmemlen = bufferlen;
	}
	SDL_strlcpy(SDL_envmem, variable, bufferlen);
	value = SDL_envmem + (sep - variable);
	*value++ = '\0';
	if ( !SetEnvironmentVariable(SDL_envmem, *value ? value : NULL) ) {
		return -1;
	}
	return 0;
}
コード例 #5
0
ファイル: SDL_pandora.c プロジェクト: g-truc/shooter
int
PND_gl_loadlibrary(_THIS, const char *path)
{
    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;

    /* Check if OpenGL ES library is specified for GF driver */
    if (path == NULL) {
        path = SDL_getenv("SDL_OPENGL_LIBRARY");
        if (path == NULL) {
            path = SDL_getenv("SDL_OPENGLES_LIBRARY");
        }
    }

    /* Check if default library loading requested */
    if (path == NULL) {
        /* Already linked with GF library which provides egl* subset of  */
        /* functions, use Common profile of OpenGL ES library by default */
        path = "/usr/lib/libGLES_CM.so";
    }

    /* Load dynamic library */
    _this->gl_config.dll_handle = SDL_LoadObject(path);
    if (!_this->gl_config.dll_handle) {
        /* Failed to load new GL ES library */
        SDL_SetError("PND: Failed to locate OpenGL ES library");
        return -1;
    }

    /* Store OpenGL ES library path and name */
    SDL_strlcpy(_this->gl_config.driver_path, path,
                SDL_arraysize(_this->gl_config.driver_path));

    /* New OpenGL ES library is loaded */
    return 0;
}
コード例 #6
0
ファイル: SDL_paudio.c プロジェクト: 1414648814/Torque3D
static int
OpenAudioPath(char *path, int maxlen, int flags, int classic)
{
    struct stat sb;
    int cycle = 0;
    int fd = OpenUserDefinedDevice(path, maxlen, flags);

    if (fd != -1) {
        return fd;
    }

    /* !!! FIXME: do we really need a table here? */
    while (devsettings[cycle][0] != '\0') {
        char audiopath[1024];
        SDL_snprintf(audiopath, SDL_arraysize(audiopath),
                     _PATH_DEV_DSP,
                     devsettings[cycle][0],
                     devsettings[cycle][1], devsettings[cycle][2]);

        if (stat(audiopath, &sb) == 0) {
            fd = open(audiopath, flags, 0);
            if (fd > 0) {
                if (path != NULL) {
                    SDL_strlcpy(path, audiopath, maxlen);
                }
                return fd;
            }
        }
    }
    return -1;
}
コード例 #7
0
int SDL_OpenAudioPath(char *path, int maxlen, int flags, int classic)
{
    struct stat sb;
    int         audio_fd;
    char        audiopath[1024];
    int         cycle;

    audio_fd = OpenUserDefinedDevice(path,maxlen,flags);
    if ( audio_fd != -1 ) {
        return audio_fd;
    }

    cycle    = 0;
    while( devsettings[cycle][0] != '\0' ) {
        SDL_snprintf( audiopath, SDL_arraysize(audiopath),
                 _PATH_DEV_DSP,
                 devsettings[cycle][0],
                 devsettings[cycle][1],
                 devsettings[cycle][2]);

	if ( stat(audiopath, &sb) == 0 ) {
	    audio_fd = open(audiopath, flags, 0);
	    if ( audio_fd > 0 ) {
		if ( path != NULL ) {
		    SDL_strlcpy( path, audiopath, maxlen );
		}
	        return audio_fd;
	    }
	}
    }
    return -1;
}
コード例 #8
0
ファイル: SDL_ph_gl.c プロジェクト: ahpho/wowmapviewer
int ph_GL_LoadLibrary(_THIS, const char* path)
{
    void* handle;
    int dlopen_flags=RTLD_WORLD | RTLD_GROUP;

    if (this->gl_config.dll_handle!=NULL)
    {
        return 0;
    }

    handle = dlopen(path, dlopen_flags);

    if (handle==NULL)
    {
        SDL_SetError("ph_GL_LoadLibrary(): Could not load OpenGL library");
        return -1;
    }

    this->gl_config.dll_handle = handle;
    this->gl_config.driver_loaded = 1;

    SDL_strlcpy(this->gl_config.driver_path, path, SDL_arraysize(this->gl_config.driver_path));

    return 0;
}
コード例 #9
0
ファイル: SDL_x11mouse.c プロジェクト: BITINT/DEFCON2
/* Sets the mouse acceleration from a string of the form:
	2/1/0
   The first number is the numerator, followed by the acceleration
   denumenator and threshold.
*/
static void SetMouseAccel(_THIS, const char *accel_param)
{
	int i;
	size_t len;
	int accel_value[3];
	char *mouse_param, *mouse_param_buf, *pin;

	len = SDL_strlen(accel_param)+1;
	mouse_param_buf = SDL_stack_alloc(char, len);
	if ( ! mouse_param_buf ) {
		return;
	}
	SDL_strlcpy(mouse_param_buf, accel_param, len);
	mouse_param = mouse_param_buf;

	for ( i=0; (i < 3) && mouse_param; ++i ) {
		pin = SDL_strchr(mouse_param, '/');
		if ( pin ) {
			*pin = '\0';
		}
		accel_value[i] = atoi(mouse_param);
		if ( pin ) {
			mouse_param = pin+1;
		} else {
			mouse_param = NULL;
		}
	}
	if ( mouse_param_buf ) {
		XChangePointerControl(SDL_Display, True, True,
			accel_value[0], accel_value[1], accel_value[2]);
		SDL_free(mouse_param_buf);
	}
}
コード例 #10
0
ファイル: SDL_udev.c プロジェクト: Derek-OBrien/DsdlEngine
static void get_caps(struct udev_device *dev, struct udev_device *pdev, const char *attr, unsigned long *bitmask, size_t bitmask_len)
{
    const char *value;
    char text[4096];
    char *word;
    int i;
    unsigned long v;

    SDL_memset(bitmask, 0, bitmask_len*sizeof(*bitmask));
    value = _this->udev_device_get_sysattr_value(pdev, attr);
    if (!value) {
        return;
    }

    SDL_strlcpy(text, value, sizeof(text));
    i = 0;
    while ((word = SDL_strrchr(text, ' ')) != NULL) {
        v = SDL_strtoul(word+1, NULL, 16);
        if (i < bitmask_len) {
            bitmask[i] = v;
        }
        ++i;
        *word = '\0';
    }
    v = SDL_strtoul(text, NULL, 16);
    if (i < bitmask_len) {
        bitmask[i] = v;
    }
}
コード例 #11
0
ファイル: ResourceSerializer.cpp プロジェクト: olowal/neko
void ResourceSerializer::SerializeToBinary(const char* szReadPath, const char* szSavePath, const char* szFilename)
{
	FileSystem::FileData fileData(255);
	FileSystem::GetListOfFiles(szReadPath, "*.tga", fileData);

	SDL_RWops* pRW = NULL;

	if(szSavePath != NULL)
	{
		const size_t uSize = 255;
		char sFullPath[uSize];
		SDL_strlcpy(sFullPath, szSavePath, uSize);
		SDL_strlcat(sFullPath, szFilename, uSize);
		pRW = SDL_RWFromFile(sFullPath, "wb");
	}
	else
	{
		pRW = SDL_RWFromFile(szFilename, "wb");
	}

	ASSERT(pRW != NULL);
	SDL_RWwrite(pRW, &s_szWatermark[0], SDL_strlen(s_szWatermark) * sizeof(char), 1);

	for(auto it = fileData.Begin(); !it.IsEnd(); ++it)
	{
		IMGHeader imgHeader;
		SDL_Surface* pSurface = IMG_tga::Load((*it), &imgHeader);
		if(pSurface != NULL)
		{
			imgHeader.hasPalette = pSurface->format->palette != NULL ? true : false;

			U8String sName;
			str::GetFilenameAsIs((*it), sName);
			StringCRC hash(sName.CStr());
			int iSize = (imgHeader.width * imgHeader.height) * 4;
			uint32 uHashName = hash.Get();
			uint32 uBlockSize = (uint32)(sizeof(neko::IMGHeader) + ((size_t)iSize) * sizeof(Uint8)) + (imgHeader.hasPalette ? sizeof(neko::IMGPalette) : (size_t)0);
			
			SDL_RWwrite(pRW, &uBlockSize, sizeof(uint32), 1);
			SDL_RWwrite(pRW, &uHashName, sizeof(uint32), 1);
			SDL_RWwrite(pRW, &imgHeader, sizeof(neko::IMGHeader), 1);

			if(imgHeader.hasPalette)
			{
				IMGPalette palette;
				palette.ncolor = pSurface->format->palette->ncolors;
				Color::Copy(palette.color, *pSurface->format->palette->colors);

				SDL_RWwrite(pRW, &palette, sizeof(neko::IMGPalette), 1);
			}
			
			SDL_RWwrite(pRW, pSurface->pixels, iSize * sizeof(Uint8), 1);
		}
	}

	uint32 uEnd = 0;
	SDL_RWwrite(pRW, &uEnd, sizeof(uint32), 1);

	SDL_RWclose(pRW);
}
コード例 #12
0
ファイル: SDL_syscdrom.c プロジェクト: ahpho/wowmapviewer
int  SDL_SYS_CDInit(void)
{
	static char *checklist[] = {
#if defined(__OPENBSD__)
		"?0 cd?c", "cdrom", NULL
#elif defined(__NETBSD__)
		"?0 cd?d", "?0 cd?c", "cdrom", NULL
#else
		"?0 cd?c", "?0 acd?c", "cdrom", NULL
#endif
	};
	char *SDLcdrom;
	int i, j, exists;
	char drive[32];
	struct stat stbuf;

	/* Fill in our driver capabilities */
	SDL_CDcaps.Name = SDL_SYS_CDName;
	SDL_CDcaps.Open = SDL_SYS_CDOpen;
	SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
	SDL_CDcaps.Status = SDL_SYS_CDStatus;
	SDL_CDcaps.Play = SDL_SYS_CDPlay;
	SDL_CDcaps.Pause = SDL_SYS_CDPause;
	SDL_CDcaps.Resume = SDL_SYS_CDResume;
	SDL_CDcaps.Stop = SDL_SYS_CDStop;
	SDL_CDcaps.Eject = SDL_SYS_CDEject;
	SDL_CDcaps.Close = SDL_SYS_CDClose;

	/* Look in the environment for our CD-ROM drive list */
	SDLcdrom = SDL_getenv("SDL_CDROM");	/* ':' separated list of devices */
	if ( SDLcdrom != NULL ) {
		char *cdpath, *delim;
		size_t len = SDL_strlen(SDLcdrom)+1;
		cdpath = SDL_stack_alloc(char, len);
		if ( cdpath != NULL ) {
			SDL_strlcpy(cdpath, SDLcdrom, len);
			SDLcdrom = cdpath;
			do {
				delim = SDL_strchr(SDLcdrom, ':');
				if ( delim ) {
					*delim++ = '\0';
				}
				if ( CheckDrive(SDLcdrom, &stbuf) > 0 ) {
					AddDrive(SDLcdrom, &stbuf);
				}
				if ( delim ) {
					SDLcdrom = delim;
				} else {
					SDLcdrom = NULL;
				}
			} while ( SDLcdrom );
			SDL_stack_free(cdpath);
		}

		/* If we found our drives, there's nothing left to do */
		if ( SDL_numcds > 0 ) {
			return(0);
		}
	}
コード例 #13
0
int
WIN_GL_LoadLibrary(_THIS, const char *path)
{
    LPTSTR wpath;
    HANDLE handle;

    if (path == NULL) {
        path = SDL_getenv("SDL_OPENGL_LIBRARY");
    }
    if (path == NULL) {
        path = DEFAULT_OPENGL;
    }
    wpath = WIN_UTF8ToString(path);
    _this->gl_config.dll_handle = LoadLibrary(wpath);
    SDL_free(wpath);
    if (!_this->gl_config.dll_handle) {
        char message[1024];
        SDL_snprintf(message, SDL_arraysize(message), "LoadLibrary(\"%s\")",
                     path);
        WIN_SetError(message);
        return -1;
    }
    SDL_strlcpy(_this->gl_config.driver_path, path,
                SDL_arraysize(_this->gl_config.driver_path));

    /* Allocate OpenGL memory */
    _this->gl_data =
        (struct SDL_GLDriverData *) SDL_calloc(1,
                                               sizeof(struct
                                                      SDL_GLDriverData));
    if (!_this->gl_data) {
        SDL_OutOfMemory();
        return -1;
    }

    /* Load function pointers */
    handle = _this->gl_config.dll_handle;
    _this->gl_data->wglGetProcAddress = (void *(WINAPI *) (const char *))
        GetProcAddress(handle, "wglGetProcAddress");
    _this->gl_data->wglCreateContext = (HGLRC(WINAPI *) (HDC))
        GetProcAddress(handle, "wglCreateContext");
    _this->gl_data->wglDeleteContext = (BOOL(WINAPI *) (HGLRC))
        GetProcAddress(handle, "wglDeleteContext");
    _this->gl_data->wglMakeCurrent = (BOOL(WINAPI *) (HDC, HGLRC))
        GetProcAddress(handle, "wglMakeCurrent");
    _this->gl_data->wglShareLists = (BOOL(WINAPI *) (HGLRC, HGLRC))
        GetProcAddress(handle, "wglShareLists");

    if (!_this->gl_data->wglGetProcAddress ||
        !_this->gl_data->wglCreateContext ||
        !_this->gl_data->wglDeleteContext ||
        !_this->gl_data->wglMakeCurrent) {
        SDL_SetError("Could not retrieve OpenGL functions");
        SDL_UnloadObject(handle);
        return -1;
    }

    return 0;
}
コード例 #14
0
ファイル: SDL_mouse.c プロジェクト: Avin15/dospad
int
SDL_AddMouse(const SDL_Mouse * mouse, char *name, int pressure_max,
             int pressure_min, int ends)
{
    SDL_Mouse **mice;
    int selected_mouse;
    int index;
    size_t length;

    if (SDL_GetMouseIndexId(mouse->id) != -1) {
        SDL_SetError("Mouse ID already in use");
    }

    /* Add the mouse to the list of mice */
    mice = (SDL_Mouse **) SDL_realloc(SDL_mice,
                                      (SDL_num_mice + 1) * sizeof(*mice));
    if (!mice) {
        SDL_OutOfMemory();
        return -1;
    }

    SDL_mice = mice;
    index = SDL_num_mice++;

    SDL_mice[index] = (SDL_Mouse *) SDL_malloc(sizeof(*SDL_mice[index]));
    if (!SDL_mice[index]) {
        SDL_OutOfMemory();
        return -1;
    }
    *SDL_mice[index] = *mouse;

    /* we're setting the mouse properties */
    length = 0;
    length = SDL_strlen(name);
    SDL_mice[index]->focus = 0;
    SDL_mice[index]->name = SDL_malloc((length + 2) * sizeof(char));
    SDL_strlcpy(SDL_mice[index]->name, name, length + 1);
    SDL_mice[index]->pressure_max = pressure_max;
    SDL_mice[index]->pressure_min = pressure_min;
    SDL_mice[index]->cursor_shown = SDL_TRUE;
    selected_mouse = SDL_SelectMouse(index);
    SDL_mice[index]->cur_cursor = NULL;
    SDL_mice[index]->def_cursor =
        SDL_CreateCursor(default_cdata, default_cmask, DEFAULT_CWIDTH,
                         DEFAULT_CHEIGHT, DEFAULT_CHOTX, DEFAULT_CHOTY);
    SDL_SetCursor(SDL_mice[index]->def_cursor);
    /* we're assuming that all mice are in the computer sensing zone */
    SDL_mice[index]->proximity = SDL_TRUE;
    /* we're assuming that all mice are working in the absolute position mode
       thanx to that, the users that don't want to use many mice don't have to
       worry about anything */
    SDL_mice[index]->relative_mode = SDL_FALSE;
    SDL_mice[index]->current_end = 0;
    SDL_mice[index]->total_ends = ends;
    SDL_SelectMouse(selected_mouse);

    return index;
}
コード例 #15
0
int  SDL_SYS_CDInit(void)
{
    struct {
	char *dir;
	char *name;
    } checklist[] = {
	{"/dev/rdisk", "cdrom"},
	{"/dev", "rrz"},
	{NULL, NULL}};
    char drive[32];
    char *SDLcdrom;
    int i, j, exists;
    struct stat stbuf;

    
    SDL_CDcaps.Name   = SDL_SYS_CDName;
    SDL_CDcaps.Open   = SDL_SYS_CDOpen;
    SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
    SDL_CDcaps.Status = SDL_SYS_CDStatus;
    SDL_CDcaps.Play   = SDL_SYS_CDPlay;
    SDL_CDcaps.Pause  = SDL_SYS_CDPause;
    SDL_CDcaps.Resume = SDL_SYS_CDResume;
    SDL_CDcaps.Stop   = SDL_SYS_CDStop;
    SDL_CDcaps.Eject  = SDL_SYS_CDEject;
    SDL_CDcaps.Close  = SDL_SYS_CDClose;


    
    SDLcdrom = SDL_getenv("SDL_CDROM");	
    if ( SDLcdrom != NULL ) {
	char *cdpath, *delim;
	size_t len = SDL_strlen(SDLcdrom)+1;
	cdpath = SDL_stack_alloc(char, len);
	if ( cdpath != NULL ) {
	    SDL_strlcpy(cdpath, SDLcdrom, len);
	    SDLcdrom = cdpath;
	    do {
		delim = SDL_strchr(SDLcdrom, ':');
		if ( delim ) {
		    *delim++ = '\0';
		}
		if ( CheckDrive(SDLcdrom, &stbuf) > 0 ) {
		    AddDrive(SDLcdrom, &stbuf);
		}
		if ( delim ) {
		    SDLcdrom = delim;
		} else {
		    SDLcdrom = NULL;
		}
	    } while ( SDLcdrom );
	    SDL_stack_free(cdpath);
	}

	
	if ( SDL_numcds > 0 ) {
	    return(0);
	}
    }
コード例 #16
0
char *SDL_strdup(const char *string)
{
    size_t len = SDL_strlen(string)+1;
    char *newstr = SDL_malloc(len);
    if ( newstr ) {
        SDL_strlcpy(newstr, string, len);
    }
    return newstr;
}
コード例 #17
0
ファイル: global.c プロジェクト: csusbdt/441-2016
const char * resource_path(const char * path) {
	if (SDL_strlcpy(dir, resource_dir, MAX_PATH) >= MAX_PATH) {
		fatal("Resource dir pathname too long: %s", resource_dir);
	}
	if (SDL_strlcat(dir, path, MAX_PATH) >= MAX_PATH) {
		fatal("Resource file pathname too long: %s%s", resource_dir, path);
	}
	return dir;
}
コード例 #18
0
size_t SDL_strlcat(char *dst, const char *src, size_t maxlen)
{
    size_t dstlen = SDL_strlen(dst);
    size_t srclen = SDL_strlen(src);
    if ( dstlen < maxlen ) {
        SDL_strlcpy(dst+dstlen, src, maxlen-dstlen);
    }
    return dstlen+srclen;
}
コード例 #19
0
ファイル: global.c プロジェクト: cbhuber/Games
void prepend_pref_path(char * dst, const char * src, int maxlen) {
	if (SDL_strlcpy(dst, pref_path, maxlen) >= maxlen) {
		fatal("not enough space for pref_path");
	}
	if (SDL_strlcat(dst, src, maxlen) >= maxlen) {
		char * msg = string_cat(src, " too long");
		fatal(msg);
	}
}
コード例 #20
0
ファイル: SDL_sysjoystick.c プロジェクト: 03050903/Torque3D
static int
IsJoystick(int fd, char *namebuf, const size_t namebuflen, SDL_JoystickGUID *guid)
{
    struct input_id inpid;
    Uint16 *guid16 = (Uint16 *) ((char *) &guid->data);

#if !SDL_USE_LIBUDEV
    /* When udev is enabled we only get joystick devices here, so there's no need to test them */
    unsigned long evbit[NBITS(EV_MAX)] = { 0 };
    unsigned long keybit[NBITS(KEY_MAX)] = { 0 };
    unsigned long absbit[NBITS(ABS_MAX)] = { 0 };

    if ((ioctl(fd, EVIOCGBIT(0, sizeof(evbit)), evbit) < 0) ||
        (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) ||
        (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) < 0)) {
        return (0);
    }

    if (!(test_bit(EV_KEY, evbit) && test_bit(EV_ABS, evbit) &&
          test_bit(ABS_X, absbit) && test_bit(ABS_Y, absbit))) {
        return 0;
    }
#endif

    if (ioctl(fd, EVIOCGNAME(namebuflen), namebuf) < 0) {
        return 0;
    }

    if (ioctl(fd, EVIOCGID, &inpid) < 0) {
        return 0;
    }

#ifdef DEBUG_JOYSTICK
    printf("Joystick: %s, bustype = %d, vendor = 0x%x, product = 0x%x, version = %d\n", namebuf, inpid.bustype, inpid.vendor, inpid.product, inpid.version);
#endif

    SDL_memset(guid->data, 0, sizeof(guid->data));

    /* We only need 16 bits for each of these; space them out to fill 128. */
    /* Byteswap so devices get same GUID on little/big endian platforms. */
    *(guid16++) = SDL_SwapLE16(inpid.bustype);
    *(guid16++) = 0;

    if (inpid.vendor && inpid.product && inpid.version) {
        *(guid16++) = SDL_SwapLE16(inpid.vendor);
        *(guid16++) = 0;
        *(guid16++) = SDL_SwapLE16(inpid.product);
        *(guid16++) = 0;
        *(guid16++) = SDL_SwapLE16(inpid.version);
        *(guid16++) = 0;
    } else {
        SDL_strlcpy((char*)guid16, namebuf, sizeof(guid->data) - 4);
    }

    return 1;
}
コード例 #21
0
ファイル: SDL_compat.c プロジェクト: jjgod/SDL
char *
SDL_VideoDriverName(char *namebuf, int maxlen)
{
    const char *name = SDL_GetCurrentVideoDriver();
    if (name) {
        SDL_strlcpy(namebuf, name, maxlen);
        return namebuf;
    }
    return NULL;
}
コード例 #22
0
ファイル: SDL_x11video.c プロジェクト: 00wendi00/MyProject
/* Find out what class name we should use */
static char *get_classname(char *classname, int maxlen)
{
	char *spot;
#if defined(__LINUX__) || defined(__FREEBSD__)
	char procfile[1024];
	char linkfile[1024];
	int linksize;
#endif

	/* First allow environment variable override */
	spot = SDL_getenv("SDL_VIDEO_X11_WMCLASS");
	if ( spot ) {
		SDL_strlcpy(classname, spot, maxlen);
		return classname;
	}

	/* Next look at the application's executable name */
#if defined(__LINUX__) || defined(__FREEBSD__)
#if defined(__LINUX__)
	SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/exe", getpid());
#elif defined(__FREEBSD__)
	SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/file", getpid());
#else
#error Where can we find the executable name?
#endif
	linksize = readlink(procfile, linkfile, sizeof(linkfile)-1);
	if ( linksize > 0 ) {
		linkfile[linksize] = '\0';
		spot = SDL_strrchr(linkfile, '/');
		if ( spot ) {
			SDL_strlcpy(classname, spot+1, maxlen);
		} else {
			SDL_strlcpy(classname, linkfile, maxlen);
		}
		return classname;
	}
#endif /* __LINUX__ */

	/* Finally use the default we've used forever */
	SDL_strlcpy(classname, "SDL_App", maxlen);
	return classname;
}
コード例 #23
0
static char *get_classname(char *classname, int maxlen)
{
	char *spot;
#if defined(__LINUX__) || defined(__FREEBSD__)
	char procfile[1024];
	char linkfile[1024];
	int linksize;
#endif

	
	spot = SDL_getenv("SDL_VIDEO_X11_WMCLASS");
	if ( spot ) {
		SDL_strlcpy(classname, spot, maxlen);
		return classname;
	}

	
#if defined(__LINUX__) || defined(__FREEBSD__)
#if defined(__LINUX__)
	SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/exe", getpid());
#elif defined(__FREEBSD__)
	SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/file", getpid());
#else
#error Where can we find the executable name?
#endif
	linksize = readlink(procfile, linkfile, sizeof(linkfile)-1);
	if ( linksize > 0 ) {
		linkfile[linksize] = '\0';
		spot = SDL_strrchr(linkfile, '/');
		if ( spot ) {
			SDL_strlcpy(classname, spot+1, maxlen);
		} else {
			SDL_strlcpy(classname, linkfile, maxlen);
		}
		return classname;
	}
#endif 

	
	SDL_strlcpy(classname, "SDL_App", maxlen);
	return classname;
}
コード例 #24
0
ファイル: global.c プロジェクト: csusbdt/441-2016
const char * save_path(const char * path) {
	int maxlen;

	if (SDL_strlcpy(dir, save_dir, MAX_PATH) >= MAX_PATH) {
		fatal("Save dir pathname too long: %s", save_dir);
	}
	if (SDL_strlcat(dir, path, MAX_PATH) >= MAX_PATH) {
		fatal("Save file pathname too long: %s%s", save_dir, path);
	}
	return dir;
}
コード例 #25
0
int
stdlib_strlcpy(void *arg)
{
  size_t result;
  char text[1024];
  const char *expected;

  result = SDL_strlcpy(text, "foo", sizeof(text));
  expected = "foo";
  SDLTest_AssertPass("Call to SDL_strlcpy(\"foo\")");
  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
  SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);

  result = SDL_strlcpy(text, "foo", 2);
  expected = "f";
  SDLTest_AssertPass("Call to SDL_strlcpy(\"foo\") with buffer size 2");
  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
  SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", result);

  return TEST_COMPLETED;
}
コード例 #26
0
ファイル: SDL_sysloadso.c プロジェクト: 0-wiz-0/mame
void *
SDL_LoadFunction(void *handle, const char *name)
{
    void *symbol = (void *) GetProcAddress((HMODULE) handle, name);
    if (symbol == NULL) {
        char errbuf[512];
        SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf));
        SDL_strlcat(errbuf, name, SDL_arraysize(errbuf));
        WIN_SetError(errbuf);
    }
    return symbol;
}
コード例 #27
0
ファイル: SDL_touch.c プロジェクト: DarkWolk/libsdl
int
SDL_AddTouch(const SDL_Touch * touch, char *name)
{
    SDL_Touch **touchPads;
    int index;
    size_t length;

    if (SDL_GetTouchIndexId(touch->id) != -1) {
        SDL_SetError("Touch ID already in use");
    }

    /* Add the touch to the list of touch */
    touchPads = (SDL_Touch **) SDL_realloc(SDL_touchPads,
                                      (SDL_num_touch + 1) * sizeof(*touch));
    if (!touchPads) {
        SDL_OutOfMemory();
        return -1;
    }

    SDL_touchPads = touchPads;
    index = SDL_num_touch++;

    SDL_touchPads[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touchPads[index]));
    if (!SDL_touchPads[index]) {
        SDL_OutOfMemory();
        return -1;
    }
    SDL_memcpy(SDL_touchPads[index], touch, sizeof(*touch));

    /* we're setting the touch properties */
    length = 0;
    length = SDL_strlen(name);
    SDL_touchPads[index]->focus = 0;
    SDL_touchPads[index]->name = SDL_malloc((length + 2) * sizeof(char));
    SDL_strlcpy(SDL_touchPads[index]->name, name, length + 1);   

    SDL_touchPads[index]->num_fingers = 0;
    SDL_touchPads[index]->max_fingers = 1;
    SDL_touchPads[index]->fingers = (SDL_Finger **) SDL_malloc(sizeof(SDL_Finger*));
    SDL_touchPads[index]->fingers[0] = NULL;
    SDL_touchPads[index]->buttonstate = 0;
    SDL_touchPads[index]->relative_mode = SDL_FALSE;
    SDL_touchPads[index]->flush_motion = SDL_FALSE;
    
    SDL_touchPads[index]->xres = (1<<(16-1));
    SDL_touchPads[index]->yres = (1<<(16-1));
    SDL_touchPads[index]->pressureres = (1<<(16-1));
    //Do I want this here? Probably
    SDL_GestureAddTouch(SDL_touchPads[index]);

    return index;
}
コード例 #28
0
ファイル: SDL_string.c プロジェクト: phossy/bloq
size_t
SDL_strlcat(char *dst, const char *src, size_t maxlen)
{
#if defined(HAVE_STRLCAT)
    return strlcat(dst, src, maxlen);
#else
    size_t dstlen = SDL_strlen(dst);
    size_t srclen = SDL_strlen(src);
    if (dstlen < maxlen) {
        SDL_strlcpy(dst + dstlen, src, maxlen - dstlen);
    }
    return dstlen + srclen;
#endif /* HAVE_STRLCAT */
}
コード例 #29
0
ファイル: SDL_compat.c プロジェクト: Blitzoreo/pcsx2-online
const char *
SDL_AudioDriverName(char *namebuf, int maxlen)
{
    const char *name = SDL_GetCurrentAudioDriver();
    if (name) {
        if (namebuf) {
            SDL_strlcpy(namebuf, name, maxlen);
            return namebuf;
        } else {
            return name;
        }
    }
    return NULL;
}
コード例 #30
0
ファイル: SDL_string.c プロジェクト: phossy/bloq
char *
SDL_strdup(const char *string)
{
#if defined(HAVE_STRDUP)
    return strdup(string);
#else
    size_t len = SDL_strlen(string) + 1;
    char *newstr = SDL_malloc(len);
    if (newstr) {
        SDL_strlcpy(newstr, string, len);
    }
    return newstr;
#endif /* HAVE_STRDUP */
}