예제 #1
0
void setcolor (int n,int m)
{
   if (m==1) attr_set (A_BOLD,0,0);
   else attr_set (A_NORMAL,0,0);
   color_set (n,0);
   if ((nocolor==1) && ((n==2) || (n==3) || (n==5) || (n==7) || (n==10) || (n==11) || (n==12) || (n==13))) attrset (A_REVERSE);
}
예제 #2
0
int sys_lsetxattr (const char *path, const char *uname, const void *value, size_t size, int flags)
{
	const char *name = prefix(uname);
#if defined(HAVE_LSETXATTR)
	return lsetxattr(path, name, value, size, flags);
#elif defined(HAVE_SETXATTR) && defined(XATTR_ADD_OPT)
	int options = XATTR_NOFOLLOW;
	return setxattr(path, name, value, size, 0, options);
#elif defined(LSETEA)
	return lsetea(path, name, value, size, flags);
#elif defined(HAVE_EXTATTR_SET_LINK)
	int retval = 0;
	if (flags) {
		/* Check attribute existence */
		retval = extattr_get_link(path, EXTATTR_NAMESPACE_USER, uname, NULL, 0);
		if (retval < 0) {
			/* REPLACE attribute, that doesn't exist */
			if (flags & XATTR_REPLACE && errno == ENOATTR) {
				errno = ENOATTR;
				return -1;
			}
			/* Ignore other errors */
		}
		else {
			/* CREATE attribute, that already exists */
			if (flags & XATTR_CREATE) {
				errno = EEXIST;
				return -1;
			}
		}
	}

	retval = extattr_set_link(path, EXTATTR_NAMESPACE_USER, uname, value, size);
	return (retval < 0) ? -1 : 0;
#elif defined(HAVE_ATTR_SET)
	int myflags = ATTR_DONTFOLLOW;
	char *attrname = strchr(name,'.') + 1;
	
	if (strncmp(name, "system", 6) == 0) myflags |= ATTR_ROOT;
	if (flags & XATTR_CREATE) myflags |= ATTR_CREATE;
	if (flags & XATTR_REPLACE) myflags |= ATTR_REPLACE;

	return attr_set(path, attrname, (const char *)value, size, myflags);
#elif defined(HAVE_ATTROPEN)
	int ret = -1;
	int myflags = O_RDWR | AT_SYMLINK_NOFOLLOW;
	int attrfd;
	if (flags & XATTR_CREATE) myflags |= O_EXCL;
	if (!(flags & XATTR_REPLACE)) myflags |= O_CREAT;
	attrfd = solaris_attropen(path, name, myflags, (mode_t) SOLARIS_ATTRMODE);
	if (attrfd >= 0) {
		ret = solaris_write_xattr(attrfd, value, size);
		close(attrfd);
	}
	return ret;
#else
	errno = ENOSYS;
	return -1;
#endif
}
예제 #3
0
static int
VerifyXFSInodeSize(char *part, char *fstype)
{
    afs_xfs_attr_t junk;
    int length = SIZEOF_XFS_ATTR_T;
    int fd = 0;
    int code = -1;
    struct fsxattr fsx;

    if (strcmp("xfs", fstype))
	return 0;

    if (attr_set(part, AFS_XFS_ATTR, &junk, length, ATTR_ROOT) == 0) {
	if (((fd = open(part, O_RDONLY, 0)) != -1)
	    && (fcntl(fd, F_FSGETXATTRA, &fsx) == 0)) {

	    if (fsx.fsx_nextents) {
		Log("Partition %s: XFS inodes too small, exiting.\n", part);
		Log("Run xfs_size_check utility and remake partitions.\n");
	    } else
		code = 0;
	}

	if (fd > 0)
	    close(fd);
	(void)attr_remove(part, AFS_XFS_ATTR, ATTR_ROOT);
    }
    return code;
}
예제 #4
0
static int
VerifyXFSInodeSize(char *part)
{
    afs_xfs_attr_t junk;
    int length = SIZEOF_XFS_ATTR_T;
    int fd;
    int code = VERIFY_ERROR;
    struct fsxattr fsx;

    if (attr_set(part, AFS_XFS_ATTR, &junk, length, ATTR_ROOT) < 0) {
	if (errno == EPERM) {
	    printf("Must be root to run %s\n", prog);
	    exit(1);
	}
	return VERIFY_ERROR;
    }

    if ((fd = open(part, O_RDONLY, 0)) < 0)
	goto done;

    if (fcntl(fd, F_FSGETXATTRA, &fsx) < 0)
	goto done;

    if (fsx.fsx_nextents == 0)
	code = VERIFY_OK;
    else
	code = VERIFY_FIX;

  done:
    if (fd >= 0)
	close(fd);
    (void)attr_remove(part, AFS_XFS_ATTR, ATTR_ROOT);

    return code;
}
예제 #5
0
int Window::fill(int attrs)
{
  attr_t battrs;
  short pair;

  if (attr_get(&battrs, &pair, NULL) == ERR)
    return ERR;

  if (attron(attrs) == ERR)
    return ERR;

  int realw = getmaxx();
  int realh = getmaxy();

  for (int i = 0; i < realw; i++)
    for (int j = 0; j < realh; j++) {
      /* Note: mvwaddch() returns ERR here when i = realw - 1 and
       * j = realh - 1 because the cursor can't be wrapped to the next line.
       * */
      mvwaddch(p->win, j, i, ' ');
    }

  if (attr_set(battrs, pair, NULL) == ERR)
    return ERR;

  return OK;
}
예제 #6
0
// Utility function for fatal errors
void Screen::_two_second_error(const char* errstr)
{
  attr_t attrs; //used in attr_(get|set)
  short pair; //used in attr_(get|set)
  attr_get(&attrs,&pair,NULL);//save terminal state
  attron(COLOR_PAIR(c_error)|A_BLINK);
  //Locate message in center of screen if room, else (0,0)
  int maxlen,maxwid;
  mvprintw(screenHeight>1 ? screenHeight/2 : 0, //y-coordinate for message
      screenWidth>std::strlen(errstr) ? screenWidth/2-strlen(errstr)/2 : 0, //x-coordinate for message
      errstr);
  ::refresh();
  attr_set(attrs,pair,NULL);//restore terminal state
  sleep(2);
}
예제 #7
0
파일: main.c 프로젝트: meesokim/spc1000
uint8 listdir(uint8 p, uint8 c, uint8 pg)
{
	int i = pg * p;
	uint8 j = 0;
	int k = i;
	int s = 0;
	while(k--) while(data[s++] != 0);
	attr_clear();
	for(;j<pg;j++)
	{
		if (*(data+s) != 0)
			printf("%03d. %-25s\n", i+j, data+s);
		while(data[s++] != 0);
	}
	attr_set(1, 0x840+c*32, 32);
	return pg;
}
예제 #8
0
int sys_lsetxattr (const char *path, const char *name, const void *value, size_t size, int flags)
{
#if defined(HAVE_LSETXATTR)
	return lsetxattr(path, name, value, size, flags);
#elif defined(HAVE_ATTR_SET)
	int myflags = ATTR_DONTFOLLOW;
	char *attrname = strchr(name,'.') +1;
	
	if (strncmp(name, "system", 6) == 0) myflags |= ATTR_ROOT;
	if (flags & XATTR_CREATE) myflags |= ATTR_CREATE;
	if (flags & XATTR_REPLACE) myflags |= ATTR_REPLACE;

	return attr_set(path, attrname, (const char *)value, size, myflags);
#else
	errno = ENOSYS;
	return -1;
#endif
}
예제 #9
0
파일: port.cpp 프로젝트: rwbarton/crawl-1.1
void puttext(int left, int top, int right, int bottom, unsigned char *str)
{
    int orig_y, orig_x;
    attr_t attrs;
    short pair;
    getyx(stdscr, orig_y, orig_x);
    attr_get(&attrs, &pair, NULL);
    for (int y = top - 1; y <= bottom - 1; y++)
    {
        for (int x = left - 1; x <= right - 1; x++)
        {
            unsigned char chr = *str++;
            unsigned char col = *str++;
            wchar_t w = cp437[chr];
            if (w == 0) w = (wchar_t)' ';
            textcolor(col);
            mvaddnwstr(y, x, &w, 1);
        }
    }
    attr_set(attrs, pair, NULL);
    move(orig_y, orig_x);
}
예제 #10
0
int Window::fill(int attrs, int x, int y, int w, int h)
{
  attr_t battrs;
  short pair;

  if (attr_get(&battrs, &pair, NULL) == ERR)
    return ERR;

  if (attron(attrs) == ERR)
    return ERR;

  int realw = getmaxx();
  int realh = getmaxy();

  for (int i = x; i < realw && i < x + w; i++)
    for (int j = y; j < realh && j < y + h; j++)
      mvwaddch(p->win, j, i, ' ');

  if (attr_set(battrs, pair, NULL) == ERR)
    return ERR;

  return OK;
}
예제 #11
0
// Get the Archive to load from
CStream *CLibraryDb::GetMethodArchive(CLibraryStoreNameSet *symbol)
{
	// Is this a brand new symbol?
	if (symbol->FilePos == -1)
	{
		return NULL;
	}

	// Now get the attributes
	// Do this for each of the names in the symbol set
	for (int i = 0; i < symbol->GetNumRecords(); i++)
	{
		CSymbolRecord &r = symbol->GetRecord(i);

		if (!r.fields_loaded)
		{
			CDbAttributeSet attr_set(&m_database);
			attr_set.m_strFilter.Format(_T("[NameID]=%d"), r.NameID);
			attr_set.Open();
			r.fields.erase(r.fields.begin(), r.fields.end());
			while (!attr_set.IsEOF())
			{
				CSymbolField field;
				field.field_name = attr_set.m_AttName;
				field.field_default = attr_set.m_AttValue;
				field.field_type = static_cast<SymbolFieldType> (attr_set.m_DisplayFlags);
				r.fields.push_back(field);

				attr_set.MoveNext();
			}

			r.fields_loaded = TRUE;
		}
	}

	return new CStreamDb(&m_database, TRUE, symbol->FilePos);
}
예제 #12
0
int
main(int argc, char **argv)
{
    char *test_only = NULL;
    int i = 1;
    for (i = 1; i < argc; i++) {
	if (strcmp(argv[i], "-v") == 0) {
	    verbose++;
	} else if (strcmp(argv[i], "-test_only") == 0){
	    test_only = argv[++i];
	} else {
	    printf("Unknown argument %s\n", argv[i]);
	}
    }
    if (!test_only || (strcmp(test_only, "paramattr") == 0)) {
	static char extern_string[] = "int printf(string format, ...);";

#ifndef PRINTF_DEFINED
	extern int printf();
#endif
	static cod_extern_entry externs[] = 
	{
	    {"printf", (void*)(long)printf},
	    {(void*)0, (void*)0}
	};
	/* test external call */
	static char code[] = "{\
			if (attr_set(l, \"test_value\")) {\n\
				return attr_ivalue(l, \"test_value\");\n\
			}\n\
			return 0;\n\
		}";

	cod_parse_context context = new_cod_parse_context();
	cod_parse_context context2;

	cod_code gen_code;
	int (*func)(attr_list l);
	attr_list l;

	cod_assoc_externs(context, externs);
	cod_parse_for_context(extern_string, context);

	context2 = cod_copy_context(context);

	l = create_attr_list();
	set_attr(l, attr_atom_from_string("test_value"), Attr_Int4, (attr_value)15);

	cod_subroutine_declaration("int proc(attr_list l)", context);
	gen_code = cod_code_gen(code, context);
	func = (int (*)(attr_list))(long)gen_code->func;

	if ((func)(l) != 15) {
	    printf("Function didn't return 15\n");
	}
	
	cod_code_free(gen_code);
	cod_free_parse_context(context);

	cod_subroutine_declaration("int proc(attr_list l)", context2);
	gen_code = cod_code_gen(code, context2);
	func = (int (*)(attr_list))(long)gen_code->func;

	if ((func)(l) != 15) {
	    printf("Function didn't return 15\n");
	}
	free_attr_list(l);
	cod_code_free(gen_code);
	cod_free_parse_context(context2);
    }
예제 #13
0
파일: xattr.c 프로젝트: rchicoli/samba
int rep_setxattr (const char *path, const char *name, const void *value, size_t size, int flags)
{
#if defined(HAVE_SETXATTR)
#ifndef XATTR_ADDITIONAL_OPTIONS
	return setxattr(path, name, value, size, flags);
#else
/* So that we do not recursivly call this function */
#undef setxattr
	int options = 0;
	return setxattr(path, name, value, size, 0, options);
#endif
#elif defined(HAVE_SETEA)
	return setea(path, name, value, size, flags);
#elif defined(HAVE_EXTATTR_SET_FILE)
	char *s;
	int retval = 0;
	int attrnamespace = (strncmp(name, "system", 6) == 0) ? 
		EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
	const char *attrname = ((s=strchr(name, '.')) == NULL) ? name : s + 1;
	if (flags) {
		/* Check attribute existence */
		retval = extattr_get_file(path, attrnamespace, attrname, NULL, 0);
		if (retval < 0) {
			/* REPLACE attribute, that doesn't exist */
			if (flags & XATTR_REPLACE && errno == ENOATTR) {
				errno = ENOATTR;
				return -1;
			}
			/* Ignore other errors */
		}
		else {
			/* CREATE attribute, that already exists */
			if (flags & XATTR_CREATE) {
				errno = EEXIST;
				return -1;
			}
		}
	}
	retval = extattr_set_file(path, attrnamespace, attrname, value, size);
	return (retval < 0) ? -1 : 0;
#elif defined(HAVE_ATTR_SET)
	int myflags = 0;
	char *attrname = strchr(name,'.') + 1;

	if (strncmp(name, "system", 6) == 0) myflags |= ATTR_ROOT;
	if (flags & XATTR_CREATE) myflags |= ATTR_CREATE;
	if (flags & XATTR_REPLACE) myflags |= ATTR_REPLACE;

	return attr_set(path, attrname, (const char *)value, size, myflags);
#elif defined(HAVE_ATTROPEN)
	int ret = -1;
	int myflags = O_RDWR;
	int attrfd;
	if (flags & XATTR_CREATE) myflags |= O_EXCL;
	if (!(flags & XATTR_REPLACE)) myflags |= O_CREAT;
	attrfd = solaris_attropen(path, name, myflags, (mode_t) SOLARIS_ATTRMODE);
	if (attrfd >= 0) {
		ret = solaris_write_xattr(attrfd, value, size);
		close(attrfd);
	}
	return ret;
#else
	errno = ENOSYS;
	return -1;
#endif
}
예제 #14
0
int main(int argc,char** argv)
{
    printf("********************************************************\n");
    printf("this demo shows how mq_reqnotify works\n");
    printf("the father process will create a new message queue\n");
    printf("and then register for message notifying.after that\n");
    printf("it will fork two children preocesses to send msgs to \n");
    printf("itself.If the mq_reqnotify works,the father process should\n");
    printf("print out all the msgs it receives\n");
    printf("********************************************************\n");
    mq_attr_t attr;
    attr_set(&attr,8,1,1);
    mqd = mq_open("hakaze",&attr);
    message_t msg1,msg2;
    msg_init(&msg1,1,"greeting from child1!");
    msg_init(&msg2,1,"greeting from child2!");
    msg_addreceiver(&msg1,getpid());
    msg_addreceiver(&msg2,getpid());
    int loopcount = 5;
    if(argc >= 2)
    {
      loopcount = atoi(argv[1]);
    }
    if(signal(SIGALRM,myhandler) != 0)
    {
      printf("cannot catch sig: %d\n",SIGALRM);
      return 0;
    }
    if(mq_reqnotify(mqd,SIGALRM) != 0)
    {
      printf("cannot register for notify with sig: %d\n",SIGALRM);
      return 0;
    }

    if(fork() == 0)
    {
      //this is child1
      int i;
      int sendcount = 0;
      for(i = 0;i < loopcount;i++)   //send msg 16 times
      {
        if(mq_send(mqd,&msg1) == 0)
        {
          sendcount++;
        }
      }
      printf("child1 exit, sendcount:%d\n",sendcount);
      return 0;
    }
    else
    {
      //this is father
      if(fork() == 0)
      {
        //this is child2
        int i;
        int sendcount = 0;;
        for(i = 0;i < loopcount;i++)   //send msg 16 times
        {
          if(mq_send(mqd,&msg2) == 0)
          {
            sendcount++;
          }
        }
        printf("child2 exit, sendcount:%d\n",sendcount);
        return 0;
      }
    }
    while(1)
    {
      ;
    }
    mq_close(mqd);
    return 0;
}
예제 #15
0
// Write a symbol to this library
void CLibraryDb::Store(CLibraryStoreNameSet *nwSymbol, CTinyCadMultiSymbolDoc &document)
{
	// Set the busy cursor
	SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));

	// First clear out all of the old names...
	if (nwSymbol->FilePos != -1)
	{
		CDbLibNameSet name_set(&m_database);
		name_set.m_strFilter.Format(_T("[SymbolID]=%d"), nwSymbol->FilePos);
		name_set.Open();

		CString sql;
		while (!name_set.IsEOF())
		{
			sql.Format(_T("DELETE FROM [Attribute] WHERE [NameID]=%d"), name_set.m_NameID);
			m_database.Execute(sql);
			name_set.Delete();
			name_set.MoveNext();
		}
	}

	// Write the symbol data into the methods file
	CStreamDb stream(&m_database, FALSE, nwSymbol->FilePos, nwSymbol->orientation);
	CXMLWriter xml(&stream);
	document.SaveXML(xml);
	stream.Flush();

	// Recover the new symbol id
	nwSymbol->FilePos = stream.m_set.m_SymbolID;

	// Do this for each of the names in the symbol set
	for (int i = 0; i < nwSymbol->GetNumRecords(); i++)
	{
		CSymbolRecord &r = nwSymbol->GetRecord(i);

		// Write back the name...
		CDbLibNameSet name_set(&m_database);

		name_set.Open();
		name_set.AddNew();

		name_set.m_Name = r.name;
		name_set.m_SymbolID = nwSymbol->FilePos;
		name_set.m_Type = 0;
		name_set.m_Reference = r.reference;
		name_set.m_ppp = nwSymbol->ppp;
		name_set.m_Description = r.description;
		name_set.m_ShowName = static_cast<int> (r.name_type);
		name_set.m_ShowRef = static_cast<int> (r.ref_type);

		name_set.Update();

		// Now recover the name this was associated with...
		name_set.MoveLast();

		// First delete the old attributes
		CString sql;
		sql.Format(_T("DELETE FROM [Attribute] WHERE [NameID]=%d"), name_set.m_NameID);
		m_database.Execute(sql);

		// Now write back the attributes...
		CDbAttributeSet attr_set(&m_database);
		attr_set.Open();
		std::vector<CSymbolField>::iterator it = r.fields.begin();
		while (it != r.fields.end())
		{
			attr_set.AddNew();
			attr_set.m_NameID = name_set.m_NameID;
			attr_set.m_AttName = (*it).field_name;
			attr_set.m_AttValue = (*it).field_default;
			attr_set.m_DisplayFlags = static_cast<int> ( (*it).field_type);
			attr_set.Update();
			++it;
		}
	}

	// Inform the design it has been saved
	document.SetModifiedFlag(FALSE);

	// Re-load the library now it has changed
	ReRead();

	SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
}