예제 #1
0
파일: lfs.c 프로젝트: lohool/OLA
 static const char *mode2string (unsigned short mode) { 
 #else 
 static const char *mode2string (mode_t mode) { 
 #endif 
   if ( S_ISREG(mode) ) 
     return "file"; 
   else if ( S_ISDIR(mode) ) 
     return "directory"; 
   else if ( S_ISLNK(mode) ) 
         return "link"; 
   else if ( S_ISSOCK(mode) ) 
     return "socket"; 
   else if ( S_ISFIFO(mode) ) 
         return "named pipe"; 
   else if ( S_ISCHR(mode) ) 
         return "char device"; 
   else if ( S_ISBLK(mode) ) 
         return "block device"; 
   else 
         return "other"; 
 } 
 

 

 /* 
 ** Set access time and modification values for file 
 */ 
 static int file_utime (lua_State *L) { 
         const char *file = luaL_checkstring (L, 1); 
         struct utimbuf utb, *buf; 
 

         if (lua_gettop (L) == 1) /* set to current date/time */ 
                 buf = NULL; 
         else { 
                 utb.actime = (time_t)luaL_optnumber (L, 2, 0); 
                 utb.modtime = (time_t) luaL_optinteger (L, 3, utb.actime); 
                 buf = &utb; 
         } 
         if (utime (file, buf)) { 
                 lua_pushnil (L); 
                 lua_pushfstring (L, "%s", strerror (errno)); 
                 return 2; 
         } 
         lua_pushboolean (L, 1); 
         return 1; 
 } 
 

 

 /* inode protection mode */ 
 static void push_st_mode (lua_State *L, STAT_STRUCT *info) { 
         lua_pushstring (L, mode2string (info->st_mode)); 
 } 
/**
* Sends pin configuration to Debug serial port. For debugging only
*/
void FirmataClientClass::printCapabilities()
{
	DBG_PORT.println(__PRETTY_FUNCTION__);
	for (int i = 0; i < MAX_PINS; i++) {
		if (pins[i].available) {
			DBG_PORT.printf("Pin %d modes\r\n", i);
			for (int j = 0; j < NUMBER_OF_MODES; j++) {
				if (pins[i].capability[j].supported) {
					DBG_PORT.printf("  Mode: %d = %s, resolution: %d", j, mode2string(j).c_str(), pins[i].capability[j].resolution);
					if (j == ANALOG) {
						DBG_PORT.printf(", analog channel: %d", pins[i].analogChannel);
					}
					DBG_PORT.println();
				}
			}
		}
	}
}
예제 #3
0
파일: libfs.c 프로젝트: nborko/oslua
static int pStat(lua_State *L)
{
    struct stat info;

    const char *file;
    char mode_str[10];

    if (lua_isstring(L, 1))
	file = lua_tostring(L, 1);
    else
	return( pusherror(L, "stat(string);" ) );

    if (stat(file, &info))
	return( pusherror(L, "stat() failed" ) );

    sprintf(mode_str,"%o", (0xfff & info.st_mode) );

    lua_newtable (L);

    /* device inode resides on */
    lua_pushliteral (L, "dev");
    lua_pushnumber (L, (lua_Number)info.st_dev);
    lua_rawset (L, -3);

    /* inode's number */
    lua_pushliteral (L, "ino");
    lua_pushnumber (L, (lua_Number)info.st_ino);
    lua_rawset (L, -3);

    /* Type of entry */
    lua_pushliteral (L, "mode");
    lua_pushnumber (L,  atoi(mode_str) );
    lua_rawset (L, -3);

    /* Type of entry */
    lua_pushliteral (L, "type");
    lua_pushstring (L, mode2string (info.st_mode));
    lua_rawset (L, -3);

    /* number of hard links to the file */
    lua_pushliteral (L, "nlink");
    lua_pushnumber (L, (lua_Number)info.st_nlink);
    lua_rawset (L, -3);

    /* user-id of owner */
    lua_pushliteral (L, "uid");
    lua_pushnumber (L, (lua_Number)info.st_uid);
    lua_rawset (L, -3);

    /* group-id of owner */
    lua_pushliteral (L, "gid");
    lua_pushnumber (L, (lua_Number)info.st_gid);
    lua_rawset (L, -3);

    /* device type, for special file inode */
    lua_pushliteral (L, "rdev");
    lua_pushnumber (L, (lua_Number)info.st_rdev);
    lua_rawset (L, -3);

    /* time of last access */
    lua_pushliteral (L, "access");
    lua_pushnumber (L, info.st_atime);
    lua_rawset (L, -3);

    /* time of last data modification */
    lua_pushliteral (L, "modification");
    lua_pushnumber (L, info.st_mtime);
    lua_rawset (L, -3);

    /* time of last file status change */
    lua_pushliteral (L, "change");
    lua_pushnumber (L, info.st_ctime);
    lua_rawset (L, -3);

    /* file size, in bytes */
    lua_pushliteral (L, "size");
    lua_pushnumber (L, (lua_Number)info.st_size);
    lua_rawset (L, -3);

    return 1;
}
예제 #4
0
    fail_unless(nicklist_add_entry(&mylist, "anotheruser@host", NULL, 0));
    fail_unless(g_list_length(mylist) == 2);
    fail_unless(find_nicklist_entry(mylist, "user@host") != NULL);
    fail_unless(find_nicklist_entry(mylist, "anonymous@host") == NULL);
    fail_unless(nicklist_remove_entry(&mylist, "user@host"));
    fail_unless(g_list_length(mylist) == 1);
    fail_unless(!nicklist_remove_entry(&mylist, "anonymous@host"));
    free_nicklist(&mylist);
    fail_unless(mylist == NULL);
END_TEST

START_TEST(test_mode2string)
    char *ret;
    irc_modes_t modes;
    modes_clear(modes);
    fail_unless(mode2string(modes) == NULL);
    modes['o'] = TRUE;
    ret = mode2string(modes);
    fail_unless(strcmp(ret, "+o") == 0);
    modes['k'] = TRUE;
    ret = mode2string(modes);
    fail_unless(strcmp(ret, "+ko") == 0);
END_TEST

Suite *state_suite(void)
{
    Suite *s = suite_create("state");
    TCase *tc_core = tcase_create("Core");
    suite_add_tcase(s, tc_core);
    tcase_add_test(tc_core, state_init);
    tcase_add_test(tc_core, state_join_me);
예제 #5
0
파일: lfs.c 프로젝트: brandonhamilton/misp
/* inode protection mode */
static void push_st_mode (lua_State *L, struct yaffs_stat *info) {
	lua_pushstring (L, mode2string (info->st_mode));
}