Example #1
0
// Note: The caller must free the buffer obtained from this function.
static char *
get_control_choices (CControl *control)
{
	const char *delimiter = ", ";
	char *buffer;
	int i;

	unsigned int req_size = 0;
	unsigned int count = control->choices.count;
	for(i = 0; i < count; i++) {
		req_size += 1 + strlen(control->choices.list[i].name) + 1 + 12;
		if(i < count - 1)
			req_size += strlen(delimiter);
	}

	buffer = (char *)malloc(req_size + 1);
	memset(buffer, 0, req_size + 1);

	for(i = 0; i < control->choices.count; i++) {
		char index_buffer[13];
		sprintf(index_buffer, "[%u]", control->choices.list[i].index);

		strcat(buffer, "'");
		strcat(buffer, control->choices.list[i].name);
		strcat(buffer, "'");
		strcat(buffer, index_buffer);

		if(i < count - 1)
			strcat(buffer, delimiter);
	}

	return buffer;
}
Example #2
0
int parse_uri(char* uri, char* filename, char* cgiargs) {
    char* ptr;
    if (!strstr(uri, "cgi-bin")) {
        //static content
        strcpy(cgiargs, "");
        strcpy(filename, ".");
        strcat(filename, uri);
        if (uri[strlen(uri) - 1] == '/') {
            strcat(filename, "home.html");
        }
        return 1;
    } else {
        // dynamic content
        ptr = index(uri, '?');
        if (ptr) {
            strcpy(cgiargs, ptr + 1);
            *ptr = '\0';
        } else {
            strcpy(cgiargs, "");
        }
        strcpy(filename, ".");
        strcat(filename, uri);
        return 0;
    }
}
Example #3
0
/* frees its first arg - typical use: s = xstrconcat4(s,t,u,v); */
char *
xstrconcat4 (char *s, const char *t, const char *u, const char *v) {
     size_t len = 0;

     len = (s ? strlen(s) : 0) + (t ? strlen(t) : 0) +
		(u ? strlen(u) : 0) + (v ? strlen(v) : 0);

     if (!len)
	     return NULL;
     if (!s) {
	     s = xmalloc(len + 1);
	     *s = '\0';
     }
     else
	     s = xrealloc(s, len + 1);
     if (t)
	     strcat(s, t);
     if (u)
	     strcat(s, u);
     if (v)
	     strcat(s, v);
     return s;


}
Example #4
0
bool CVSService::setUserPassword(const char *username, const char *password)
{
	// Repository is not initialized, just return false.
	if (!m_isRepoInitialized)
		return false;

	char filename[MAX_PATH + 24];
	FILE *fp;

	// Write user name password to 'passwd' file.
	if ((fp = fopen(strcat(strcpy(filename, m_repoPath), "/CVSROOT/passwd"), "w")) == NULL)
		return false;
	fprintf(fp, "%s:%s:%s\n", username, __crypt(password), getpwuid(getuid())->pw_name);
	fclose(fp);

	// Write user name to 'reader' file.
	if ((fp = fopen(strcat(strcpy(filename, m_repoPath), "/CVSROOT/reader"), "w")) == NULL)
		return false;
	fprintf(fp, "%s\n", username);
	fclose(fp);

	// Write user name to 'writer' file.
	if ((fp = fopen(strcat(strcpy(filename, m_repoPath), "/CVSROOT/writer"), "w")) == NULL)
		return false;
	fprintf(fp, "%s\n", username);
	fclose(fp);

	// Return true.
	return true;
}
Example #5
0
// Show a requester
void global_requester(char *text)
{
	RexxRequester *req;
	char *ok_str;

	// Get OK string
	ok_str=GetString(&locale,MSG_OKAY);

	// Allocate requester argument packet
	if (req=AllocVec(sizeof(RexxRequester)+strlen(text)+strlen(ok_str)+5,MEMF_CLEAR))
	{
		// Store message
		req->command=RXCMD_REQUEST;

		// Copy string
		strcpy(req->args,"\"");
		strcat(req->args,text);
		strcat(req->args,"\" ");
		strcat(req->args,ok_str);

		// Startup requester process
		if (!(misc_startup(
			"dopus_rexx_request",
			REXX_REQUESTER,
			GUI->window,
			req,
			0))) FreeVec(req);
	}
}
Example #6
0
int read_from_dir(char *repo_name, char *prefix)
{
	DIR *dir;
	struct dirent *info_file;
	struct stat stat_file;
	char path[strlen(prefix) + strlen(repo_name) + 1];

	strcpy(path, prefix);
	if (strncmp(repo_name, "local", 5) != 0) {
		strcat(path, "/");
		strcat(path, repo_name);
	}

	if ((dir = opendir(path)) == NULL)
		return EXIT_FAILURE;

	while ((info_file = readdir(dir))) {
		char filename[strlen(path) + strlen(info_file->d_name) +
			      9];

		sprintf(filename, "%s/%s", path, info_file->d_name);
		stat(filename, &stat_file);
		if (S_ISDIR(stat_file.st_mode)
		    && info_file->d_name[0] != '.') {
			strcat(filename, "/Pkgfile");
			parse_pkgfile(filename, repo_name);
		}
	}
	closedir(dir);
	return (EXIT_SUCCESS);
}
Example #7
0
int DAPLUGCALL keyboard_addSleep(Keyboard *k, int duration){

    char duration_s[4*2+1]="";
    int added_len = 0;

    if(duration==-1){
        duration = 0xFFFF;
    }

    if(duration>0xFFFF){
        sprintf(duration_s,"%08X",duration);
    }else{
        sprintf(duration_s,"%04X",duration);
    }

    added_len = strlen("0104")+strlen(duration_s);
    added_len = added_len/2;

    if(k->currentContentSize+added_len <= MAX_KB_CONTENT_SIZE){
        if(duration > 0xFFFF) {strcat(k->content,"0104");}
        else {strcat(k->content,"0102");}
        strcat(k->content,duration_s);
        k->currentContentSize = k->currentContentSize+added_len;
    }else{
        fprintf(stderr,"\nkeyboard_addSleep(): Keyboard maximum content size exceeded !\n");
        return 0;
    }

    return 1;

}
Example #8
0
static const char *lirc_parse_relative(char *dst, size_t dst_size, const char *child, const char *current)
{
	char *dir;
	size_t dirlen;

	if (!current)
		return child;

	/* Not a relative path */
	if (*child == '/')
		return child;

	if (strlen(current) >= dst_size) {
		return NULL;
	}
	strcpy(dst, current);
	dir = dirname(dst);
	dirlen = strlen(dir);
	if (dir != dst) {
		memmove(dst, dir, dirlen + 1);
	}

	if (dirlen + 1 + strlen(child) + 1 > dst_size) {
		return NULL;
	}
	strcat(dst, "/");
	strcat(dst, child);

	return dst;
}
Example #9
0
File: debug.c Project: pvpgn/d2gs11
extern void DebugEventCallback(char const * module, int count, ...)
{
    SYSTEMTIME	st;
    va_list		ap;
    int		i,value;
    char		* name;
    char		function[MAX_LINE_LEN];

    if (!(d2gsconf.debugeventcallback)) return;
    GetLocalTime(&st);
    D2GSEventLog("DebugEventCallback","Event Called From Module \"%s\"",module);
    fprintf(hexstrm,"%d: Checking Module \"%s\" (%d)\tTime:%d.%d.%d.%d\n",\
            gdwTotalCount++,module,count,st.wHour,st.wMinute,\
            st.wSecond,st.wMilliseconds);
    sprintf (function,"%s(",module);
    va_start(ap,count);
    for (i=0; i<count; i++) {
        name=va_arg(ap, char *);
        value=va_arg(ap, int);
        strcat(function,name);
        if (i != count-1) strcat(function,", ");
        DebugDumpParam(name,value);
    }
    va_end(ap);
    strcat(function,")");
    fprintf(hexstrm,"Function: %s\n",function);
    fprintf(hexstrm,"\n\n");
    fflush(hexstrm);
    return;
}
Example #10
0
const char *R_ExpandFileName(const char *s)
{
    char *p;

    if(s[0] != '~' || (s[0] && isalpha(s[1]))) return s;
    if(HaveHOME < 0) {
	HaveHOME = 0;
	p = getenv("R_USER"); /* should be set so the rest is a safety measure */
	if(p && strlen(p) && strlen(p) < PATH_MAX) {
	    strcpy(UserHOME, p);
	    HaveHOME = 1;
	} else {
	    p = getenv("HOME");
	    if(p && strlen(p) && strlen(p) < PATH_MAX) {
		strcpy(UserHOME, p);
		HaveHOME = 1;
	    } else {
		p = getenv("HOMEDRIVE");
		if(p && strlen(p) < PATH_MAX) {
		    strcpy(UserHOME, p);
		    p = getenv("HOMEPATH");
		    if(p && strlen(UserHOME) + strlen(p) < PATH_MAX) {
			strcat(UserHOME, p);
			HaveHOME = 1;
		    }
		}
	    }
	}
    }
    if(HaveHOME > 0 && strlen(UserHOME) + strlen(s+1) < PATH_MAX) {
	strcpy(newFileName, UserHOME);
	strcat(newFileName, s+1);
	return newFileName;
    } else return s;
}
JSList *
jack_internals_load (JSList * internals) {
    char * driver_dir;
    char driver_dir_storage[512];
    char dll_filename[512];
    WIN32_FIND_DATA filedata;
    HANDLE file;
    const char * ptr = NULL;
    JSList * driver_list = NULL;
    jack_driver_desc_t * desc;

    if ((driver_dir = getenv("JACK_DRIVER_DIR")) == 0) {
        // for WIN32 ADDON_DIR is defined in JackConstants.h as relative path
        GetCurrentDirectory(512, driver_dir_storage);
        strcat(driver_dir_storage, "/");
        strcat(driver_dir_storage, ADDON_DIR);
        driver_dir = driver_dir_storage;
    }

    sprintf(dll_filename, "%s/*.dll", driver_dir);

    file = (HANDLE )FindFirstFile(dll_filename, &filedata);

    if (file == INVALID_HANDLE_VALUE) {
        jack_error("error");
        return NULL;
    }

    do {

        ptr = strrchr (filedata.cFileName, '.');
        if (!ptr) {
            continue;
        }
        ptr++;
        if (strncmp ("dll", ptr, 3) != 0) {
            continue;
        }

        /* check if dll is an internal client */
        if (!check_symbol(filedata.cFileName, "jack_internal_initialize")) {
            continue;
        }

        desc = jack_get_descriptor (internals, filedata.cFileName, "jack_get_descriptor");
        if (desc) {
            driver_list = jack_slist_append (driver_list, desc);
        } else {
            jack_error ("jack_get_descriptor returns null for \'%s\'", filedata.cFileName);
        }

    } while (FindNextFile(file, &filedata));

    if (!driver_list) {
        jack_error ("could not find any internals in %s!", driver_dir);
        return NULL;
    }

    return driver_list;
}
Example #12
0
int
getallpost(char *path)
{
	DIR *dirp;
	struct dirent *direntp;
	int h;
	dirp = opendir(path);
	if (dirp == NULL)
		return -1;
	while ((direntp = readdir(dirp)) != NULL) {
		if (direntp->d_name[0] == '.')
			continue;
		if (ispostfilename(direntp->d_name)) {
			h = hash(direntp->d_name);
			if (nfile[h] >= MAXFILE) {
				printf("啊?!");
				exit(0);
			}
			refcount[h][nfile[h]] = 0;
			strcpy(allpost[h][nfile[h]++], direntp->d_name);
			continue;
		}
		if (isspcname(direntp->d_name))
			continue;
		unknownfn++;
		if (strlen(otherfile) + strlen(direntp->d_name) + 1 <
		    sizeof (otherfile)) {
			strcat(otherfile, " ");
			strcat(otherfile, direntp->d_name);
		}
	}
	closedir(dirp);
	return 0;
}
Example #13
0
/**
 * @func set_developer_path -- set the current developer path
 * @arg path - path to set
 * @return: 0 on success, -1 on failure
 */
static int set_developer_path(const char *path)
{
	FILE *fp = NULL;
	char *pathtocfg = NULL;
	char *cfg_path = NULL;

	if ((pathtocfg = getenv("HOME")) == NULL) {
		fprintf(stderr, "xcode-select: error: failed to read HOME variable.\n");
		return -1;
	}

        cfg_path = (char *)malloc((strlen(pathtocfg) + sizeof(SDK_CFG)));

        strcat(pathtocfg, "/");
	strcat(cfg_path, strcat(pathtocfg, SDK_CFG));

	if ((fp = fopen(cfg_path, "w+")) != NULL) {
		fwrite(path, 1, strlen(path), fp);
		fclose(fp);
	} else {
		fprintf(stderr, "xcode-select: error: unable to open configuration file. (errno=%s)\n", strerror(errno));
		return -1;
	}

	free(cfg_path);

	return 0;
}
Example #14
0
// Note: The caller must free the buffer obtained from this function.
static char *
get_control_flags (CControlFlags flags)
{
	int i;

	const char *delimiter = ", ";
	const char *names[] = {
		"CAN_READ",
		"CAN_WRITE",
		"CAN_NOTIFY",
		"<Unknown>",
		"<Unknown>",
		"<Unknown>",
		"<Unknown>",
		"<Unknown>",
		"IS_CUSTOM",
		"IS_RELATIVE",
		"IS_ACTION",
	};
	char buffer[14 * ARRAY_SIZE(names)];		// 14 = maximum name length + strlen(delimiter)
	memset(buffer, 0, sizeof(buffer));

	for(i = 0; i < ARRAY_SIZE(names); i++) {
		if(flags & (1 << i)) {
			strcat(buffer, names[i]);
			if(flags >= (1 << (i + 1)))
				strcat(buffer, delimiter);
		}
	}

	return strdup(buffer);
}
Example #15
0
char *iupdrvGetSystemVersion(void)
{
  char *str = iupStrGetMemory(256);
  OSVERSIONINFOEXA osvi;
  SYSTEM_INFO si;

  ZeroMemory(&si, sizeof(SYSTEM_INFO));
  GetSystemInfo(&si);

  ZeroMemory(&osvi, sizeof(OSVERSIONINFOEXA));
  osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
  GetVersionExA((OSVERSIONINFOA*)&osvi);

  sprintf(str, "%d.%d.%d", (int)osvi.dwMajorVersion, (int)osvi.dwMinorVersion, (int)osvi.dwBuildNumber);

  /* Display service pack (if any). */
  if (osvi.szCSDVersion && osvi.szCSDVersion[0]!=0)
  {
    strcat(str, " ");
    strcat(str, osvi.szCSDVersion);
  }

  if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)
    strcat(str, " (IA64)");
  else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
    strcat(str, " (x64)");
  else
    strcat(str, " (x86)");

  return str;
}
void terminate_con(int connectid) {

	int i;
	for (i = 1; i < 4; i++) {

		if (mycon[i].con_id == connectid)
			break;
	}

	if (i == 4)
		fprintf(stderr, "\n NO SUCH CONNECTION");
	else {
		char hostnm[1024], con_msg[1024], temp[10];
		gethostname(hostnm, 1024);
		strcpy(con_msg, "terminate ");
		strcat(con_msg, hostnm);
		strcat(con_msg, " ");
		int myport = PORTNO;
		sprintf(temp, "%d", myport);
		strcat(con_msg, temp);
		strcat(con_msg, " ");
		write(mycon[i].confd, con_msg, strlen(con_msg));
		("\nTERMINATED CONNECTION:\n->HOSTNAME:%s \n->IPADDRESS:%s \n->PORTNO:%d", mycon[i].hostn, mycon[i].ip, mycon[i].port);
		mycon[i].con_id = -1;

		strcpy(mycon[i].hostn, "not_yet_added");

	}
	display_con();

}
Example #17
0
struct repolist *parse_cvsup(char *path, struct repolist *r)
{
	FILE *file;
	char *line = NULL;
	size_t n = 0;
	ssize_t nread;

	file = fopen(path, "r");
	if (file == NULL)
		return (r);

	char *prefix = NULL;
	char *mad_prefix = NULL;
	char *repo;

	while ((nread = getline(&line, &n, file)) != -1) {
		line[strlen(line) - 1] = '\0';
		trim(line);
		if (line[0] == '#' || strlen(line) == 0)
			continue;

		if (strstr(line, "*default prefix")) {
			prefix = get_value(line, "*default prefix");
			if (prefix == NULL)
				continue;
			if (strlen(prefix) <= strlen(PORTS_LOCATION))
				continue;
			if (strncmp
			    (prefix, PORTS_LOCATION,
			     strlen(PORTS_LOCATION)))
				continue;
			mad_prefix =
			    mid(prefix, strlen(PORTS_LOCATION) + 1, END);
			trim(mad_prefix);
			strcat(mad_prefix, "/");
			prefix = strdup(PORTS_LOCATION);

		}

		if (line[0] == '*')
			continue;

		if (strlen(line)) {
			if (mad_prefix) {
				repo = strdup(mad_prefix);
				strcat(repo, line);
				sed(repo, "//", "/");
			} else
				repo = strdup(line);

			strtok(repo, " ");
			r = repolist_add(repo, prefix, path, r);
		}
	}

	if (line)
		free(line);
	fclose(file);
	return (r);
}
Example #18
0
/***************************************************************************
 *
 *N  point_in_face_table
 *
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *    Test whether a point is inside a face or not.  Must have a valid path-
 *   name to a valid VPF Face file, or else be in graphics mode for the error
 *   message that will result.  Filename must have all directory seperators
 *   escapes; eg. c:\\vpf    NOT c:\vpf
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *   Parameters:
 *A
 *    x        <input> == (float) given point x coordinate.
 *    y        <input> == (float) given point y coordinate.
 *    face_id  <input> == (rspf_int32) face.
 *    fname    <input> == (char *) pathname to VPF face file.
 *    point_in_face_table <output> == VPF_BOOLEAN:
 *                                            1 --> point is inside
 *                                            0 --> point is not inside
 *E
 **************************************************************************/
int point_in_face_table( float x, float y,
			 rspf_int32 face_id,
			 char *fname )
{
   vpf_table_type facetable, ringtable, edgetable;
   char *name;
   int result;

   name = (char *)vpfmalloc( 255*sizeof(char) );

   facetable = vpf_open_table(fname,disk, "rb", NULL );

   strupr(fname);

   strcpy( name, fname );
   dirpath( name );
   strcat( name, "RNG" );
   ringtable = vpf_open_table( name, disk , "rb", NULL );

   strcpy( name, fname );
   dirpath( name );
   strcat( name, "EDG" );
   edgetable = vpf_open_table( name, disk , "rb", NULL );

   free( name );

   result = point_in_face( x, y, face_id, facetable, ringtable, edgetable );

   vpf_close_table(&facetable);
   vpf_close_table(&ringtable);
   vpf_close_table(&edgetable);

   return result;
}
Example #19
0
void NPC_PrecacheWeapons( team_t playerTeam, int spawnflags, char *NPCtype )
{
	int weapons = NPC_WeaponsForTeam( playerTeam, spawnflags, NPCtype );
	gitem_t	*item;
	for ( int curWeap = WP_SABER; curWeap < WP_NUM_WEAPONS; curWeap++ )
	{
		if ( (weapons & ( 1 << curWeap )) )
		{
			item = FindItemForWeapon( ((weapon_t)(curWeap)) );	//precache the weapon
			CG_RegisterItemSounds( (item-bg_itemlist) );
			CG_RegisterItemVisuals( (item-bg_itemlist) );
			//precache the in-hand/in-world ghoul2 weapon model

			char weaponModel[64];
			
			strcpy (weaponModel, weaponData[curWeap].weaponMdl);	
			if (char *spot = strstr(weaponModel, ".md3") ) {
				*spot = 0;
				spot = strstr(weaponModel, "_w");//i'm using the in view weapon array instead of scanning the item list, so put the _w back on
				if (!spot) {
					strcat (weaponModel, "_w");
				}
				strcat (weaponModel, ".glm");	//and change to ghoul2
			}
			gi.G2API_PrecacheGhoul2Model( weaponModel ); // correct way is item->world_model
		}
	}
}
int gpio_on(int gpio_nr)
{
	int fd;
	char gpio_number_string[8];
	char path_value[50];
	
	sprintf(gpio_number_string, "%d", gpio_nr);
	
	strcpy(path_value, "/sys/class/gpio/gpio");
	strcat(path_value, gpio_number_string);
	strcat(path_value, "/value");
	
	fd = open(path_value, O_WRONLY);
	if( fd == -1)
	{
		perror("could not open file 'value': ");
		return 1;
	}

	if(write(fd, "1", 1) == -1)
	{
		perror("could not write to file");
		close (fd);
		return 1;
	}
	
	close(fd);
	
	return 0;
}
Example #21
0
int DAPLUGCALL keyboard_addOSProbeWinR(Keyboard *k, int nb, int delay, int code){

    char nb_s[1*2+1]="",
         delay_s[2*2+1]="",
         code_s[1*2+1]="";

    int added_len = 0;

    if(nb==-1) nb = 0x14;
    if(delay == -1) delay = 0xFFFF;
    if (code == -1) code = 0x00;

    sprintf(nb_s,"%02X",nb);
    sprintf(delay_s,"%04X",delay);
    sprintf(code_s,"%02X",code);

    added_len = strlen("0204")+strlen(nb_s)+strlen(delay_s)+strlen(code_s);
    added_len = added_len/2;

    if(k->currentContentSize+added_len <= MAX_KB_CONTENT_SIZE){
        strcat(k->content,"0204");
        strcat(k->content,nb_s);
        strcat(k->content,delay_s);
        strcat(k->content,code_s);
        k->currentContentSize = k->currentContentSize + added_len;
    }
    else{
        fprintf(stderr,"\nkeyboard_addOSProbeWinR(): Keyboard maximum content size exceeded !\n");
        return 0;
    }

    return 1;
}
static size_t append_number(char* words, int num) {
  int tens_val = num / 10 % 10;
  int ones_val = num % 10;

  size_t len = 0;

  if (tens_val > 0) {
    if (tens_val == 1) {
      strcat(words, TEENS[ones_val]);
      return strlen(TEENS[ones_val]);
    }
    
    if (ones_val == 0) {
      strcat(words, TENS[tens_val]);
      len += strlen(TENS[tens_val]);
    } else {
      strcat(words, TENSPLUS[tens_val]);
      len += strlen(TENSPLUS[tens_val]);
    }
  }

  if (ones_val > 0 || num == 0) {
    strcat(words, ONES[ones_val]);
    len += strlen(ONES[ones_val]);
  }

  return len;
}
static char *conf_expand_value(const char *in)
{
	struct symbol *sym;
	const char *src;
	static char res_value[SYMBOL_MAXLENGTH];
	char *dst, name[SYMBOL_MAXLENGTH];

	res_value[0] = 0;
	dst = name;
	while ((src = strchr(in, '$'))) {
		strncat(res_value, in, src - in);
		src++;
		dst = name;
		while (isalnum(*src) || *src == '_')
			*dst++ = *src++;
		*dst = 0;
		sym = sym_lookup(name, 0);
		sym_calc_value(sym);
		strcat(res_value, sym_get_string_value(sym));
		in = src;
	}
	strcat(res_value, in);

	return res_value;
}
Example #24
0
bool read_directory_next(dir_information* dirp, char* entry_name, bool& is_directory) {
	struct dirent* dentry = readdir(dirp->dir);
	if (dentry==NULL) {
		return false;
	}

//	safe_strncpy(entry_name,dentry->d_name,(FILENAME_MAX<MAX_PATH)?FILENAME_MAX:MAX_PATH);	// [include stdio.h], maybe pathconf()
	safe_strncpy(entry_name,dentry->d_name,CROSS_LEN);

#ifdef DIRENT_HAS_D_TYPE
	if(dentry->d_type == DT_DIR) {
		is_directory = true;
		return true;
	} else if(dentry->d_type == DT_REG) {
		is_directory = false;
		return true;
	}
#endif

	//Maybe only for DT_UNKNOWN if DIRENT_HAD_D_TYPE..
	static char buffer[2 * CROSS_LEN + 1] = { 0 };
	static char split[2] = { CROSS_FILESPLIT , 0 };
	buffer[0] = 0;
	strcpy(buffer,dirp->base_path);
	size_t buflen = strlen(buffer);
	if (buflen && buffer[buflen - 1] != CROSS_FILESPLIT ) strcat(buffer, split);
	strcat(buffer,entry_name);
	struct stat status;

	if (stat(buffer,&status) == 0) is_directory = (S_ISDIR(status.st_mode)>0);
	else is_directory = false;

	return true;
}
Example #25
0
File: find.c Project: mbryk/OS
void directory(char *direct){
	DIR *dirp;
	struct dirent *de;
	int i;

	if((dirp = opendir(direct))==NULL){
		fprintf(stderr,"Error opening directory %s: %s\n", direct, strerror(errno));
		exit(-1);
	}
	while((de = readdir(dirp))!=NULL){
		char *pathname = malloc(strlen(direct)+strlen(de->d_name)+2);
		if(pathname==NULL){
			fprintf(stderr, "Error Allocating Memory. Please try again. %s\n", strerror(errno));
			exit(-1);
		}
		strcpy(pathname, direct);
		strcat(pathname, "/");
		strcat(pathname, de->d_name);
		
		if(!(i=check_file(pathname, de->d_name))){
			print_info(pathname);
		}			
		/* If device number was different or it is ".","..", stop stepping through the directory */
		if(de->d_type==DT_DIR && i!=2)
			directory(pathname);
	}

	if(closedir(dirp)<0){
		fprintf(stderr, "Error Closing Directory %s: %s\n", direct, strerror(errno));
		exit(-1);
	}
}
Example #26
0
void serialize_etiquetas(char* etiquetas, t_size size_etiquetas, char** buffer) {
	char* str = malloc(size_etiquetas+1);
	snprintf(str, size_etiquetas+1, "%c", etiquetas);
	strcat(*buffer,str);
	strcat(*buffer,"-");
	free(str);
}
Example #27
0
// where command implementation
void executeWhere(Cmd c)
{
	char *path = getenv("PATH");
	char dupPath[500],cmd_path[500]="";
	int i = -1 ;
	int j=0;
	while(j<8){
		if(!strcmp(c->args[1],builtInCommands[j])){
			i = j;
		}
		j++;
	}
	if(i!=-1)
	{
		printf("%s:built-in command\n",builtInCommands[i]);
	}	
	strcpy(dupPath,path);
	char* splittedPath = strtok(dupPath,":");
	while(splittedPath != NULL)
	{
		strcpy(cmd_path,splittedPath);
		strcat(cmd_path,"/");
		strcat(cmd_path,c->args[1]);
		if(!access(cmd_path,F_OK))
		{
		    printf("%s\n",cmd_path);
		}
		splittedPath = strtok(NULL,":");
	}
}
Example #28
0
/* Dump uptime info out to dcc (guppy 9Jan99)
 */
void tell_verbose_uptime(int idx)
{
  char s[256], s1[121];
  time_t now2, hr, min;

  now2 = now - online_since;
  s[0] = 0;
  if (now2 > 86400) {
    /* days */
    sprintf(s, "%d day", (int) (now2 / 86400));
    if ((int) (now2 / 86400) >= 2)
      strcat(s, "s");
    strcat(s, ", ");
    now2 -= (((int) (now2 / 86400)) * 86400);
  }
  hr = (time_t) ((int) now2 / 3600);
  now2 -= (hr * 3600);
  min = (time_t) ((int) now2 / 60);
  sprintf(&s[strlen(s)], "%02d:%02d", (int) hr, (int) min);
  s1[0] = 0;
  if (backgrd)
    strcpy(s1, MISC_BACKGROUND);
  else {
    if (term_z)
      strcpy(s1, MISC_TERMMODE);
    else if (con_chan)
      strcpy(s1, MISC_STATMODE);
    else
      strcpy(s1, MISC_LOGMODE);
  }
  dprintf(idx, "%s %s  (%s)\n", MISC_ONLINEFOR, s, s1);
}
Example #29
0
void
c_struct(FILE *fd, char *ipref, Symbol *z)
{	Lextok *fp, *tl;
	char pref[256], eprefix[256];
	int ix;

	ini_struct(z);

	for (ix = 0; ix < z->nel; ix++)
	for (fp = z->Sval[ix]; fp; fp = fp->rgt)
	for (tl = fp->lft; tl; tl = tl->rgt)
	{	strcpy(eprefix, ipref);
		if (z->nel > 1)
		{	/* insert index before last '.' */
			eprefix[strlen(eprefix)-1] = '\0';
			sprintf(pref, "[ %d ].", ix);
			strcat(eprefix, pref);
		}
		if (tl->sym->type == STRUCT)
		{	strcat(eprefix, tl->sym->name);
			strcat(eprefix, ".");
			c_struct(fd, eprefix, tl->sym);
		} else
			c_var(fd, eprefix, tl->sym);
	}
}
static void par_fn(char *base, int ftp, const t_commrec *cr,
                   gmx_bool bAppendSimId, gmx_bool bAppendNodeId,
                   char buf[], int bufsize)
{
    if ((size_t)bufsize < (strlen(base)+10))
    {
        gmx_mem("Character buffer too small!");
    }

    /* Copy to buf, and strip extension */
    strcpy(buf, base);
    buf[strlen(base) - strlen(ftp2ext(fn2ftp(base))) - 1] = '\0';

    if (bAppendSimId)
    {
        sprintf(buf+strlen(buf), "%d", cr->ms->sim);
    }
    if (bAppendNodeId)
    {
        strcat(buf, "_rank");
        sprintf(buf+strlen(buf), "%d", cr->nodeid);
    }
    strcat(buf, ".");

    /* Add extension again */
    strcat(buf, (ftp == efTPX) ? "tpr" : (ftp == efEDR) ? "edr" : ftp2ext(ftp));
    if (debug)
    {
        fprintf(debug, "rank %d par_fn '%s'\n", cr->nodeid, buf);
        if (fn2ftp(buf) == efLOG)
        {
            fprintf(debug, "log\n");
        }
    }
}