glibtypes.c

来自「可以播放MP3,wma等文件格式的播放器」· C语言 代码 · 共 109 行

C
109
字号
#include "glibtypes.h"#include <stdlib.h>#include <string.h>#include <unistd.h>#include <sys/param.h>#ifdef __cplusplusextern "C" {#endifchar *g_get_tmp_dir(){	static char *g_tmp_dir=0;	if (!g_tmp_dir)    {		g_tmp_dir = getenv ("TMPDIR");		if (!g_tmp_dir)			g_tmp_dir = getenv ("TMP");		if (!g_tmp_dir)			g_tmp_dir = getenv ("TEMP");		if (g_tmp_dir)			g_tmp_dir = strdup(g_tmp_dir);		else 		{#ifndef NATIVE_WIN32			g_tmp_dir = "/tmp";#else /* NATIVE_WIN32 */			g_tmp_dir = "C:\\";#endif /* NATIVE_WIN32 */		}	}	return g_tmp_dir;}guintg_list_length (GList *list){  guint length;    length = 0;  while (list)    {      length++;      list = list->next;    }    return length;}gpointerg_memdup (gconstpointer mem,		  guint byte_size){  gpointer new_mem;  if (mem)    {      new_mem = (gconstpointer) malloc (byte_size);      memcpy (new_mem, mem, byte_size);    }  else    new_mem = NULL;  return new_mem;}gchar*g_get_current_dir (void){  gchar *buffer;  gchar *dir;  buffer = (gchar *) malloc(PATH_MAX);  *buffer = 0;    /* We don't use getcwd(3) on SUNOS, because, it does a popen("pwd")   * and, if that wasn't bad enough, hangs in doing so.   */#if	defined (sun) && !defined (__SVR4)  dir = getwd (buffer);#else	/* !sun */  dir = getcwd (buffer, PATH_MAX - 1);#endif	/* !sun */    if (!dir || !*buffer)    {      /* hm, should we g_error() out here?       * this can happen if e.g. "./" has mode \0000       */      buffer[0] = G_DIR_SEPARATOR;      buffer[1] = 0;    }  dir = strdup (buffer);  free (buffer);    return dir;}#ifdef __cplusplus}#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?