예제 #1
0
static u_char
radius_id(void)
{
	int fd, n;
	u_char id;

	fd = open(RADIUS_ID_FILE, O_RDWR|O_CREAT, 0644);
	if (fd < 0) {
		syslog(LOG_ERR, "RADIUS: open %s failed: %m", RADIUS_ID_FILE);
		return magic();
	}
	if (flock(fd, LOCK_EX) != 0) {
		syslog(LOG_ERR, "RADIUS: flock %s failed: %m", RADIUS_ID_FILE);
	}

	n = read(fd, &id, 1);
	if (n < 1) {
		id = magic();
	} else {
		id++;
	}
	lseek(fd, 0L, SEEK_SET);
	write(fd, &id, 1);
    
	flock(fd, LOCK_UN);
	close(fd);

	return id;
}
예제 #2
0
u_int
radius_sessionid(void)
{
	int fd, n;
	u_char sessionid;

	fd = open(RADIUS_SESSIONID_FILE, O_RDWR|O_CREAT, 0644);
	if (fd < 0) {
		syslog(LOG_ERR, "RADIUS: open %s failed: %m", RADIUS_SESSIONID_FILE);
		return magic();
	}
	if (flock(fd, LOCK_EX) != 0) {
		syslog(LOG_ERR, "RADIUS: flock %s failed: %m", RADIUS_SESSIONID_FILE);
	}

	n = read(fd, &sessionid, sizeof(sessionid));
	if (n < sizeof(sessionid)) {
		sessionid = magic();
	} else {
		sessionid++;
	}
	lseek(fd, 0L, SEEK_SET);
	write(fd, &sessionid, sizeof(sessionid));

	flock(fd, LOCK_UN);
	close(fd);

	return sessionid;
}
예제 #3
0
int main(void)
{
   magic(1);
   magic(3);
   magic(5);
   magic(7);
   magic(9);
}//end main()
예제 #4
0
int magic(int a[],int lb, int ub){
  int mid = (lb+ub)/2;
  if(a[mid] == mid){
    return a[mid];
  }
  else if(a[mid]>mid){
    magic(a,lb,mid);
  }
  else{
    magic(a,mid+1,ub);
  }
}
예제 #5
0
파일: thread.cpp 프로젝트: jadesoul/libsoul
void thread::stop() {
	if (running) {
		running=false;
#ifdef OS_WIN32
		CloseHandle(myThread);
#else
		pthread_detach(myThread);
#endif
		magic("thread: thread stopped\n");
	} else {
		magic("thread: thread already stopped\n");
	}
}
예제 #6
0
        void GLShader::create(Block* _mem) {
            moti::MemoryReader reader(_mem->m_ptr, _mem->m_length);
            uint32_t magic(0);
            moti::read(&reader, magic);


            switch (magic) {
            case MOTI_VERTEX_SHADER_MAGIC: m_type = GL_VERTEX_SHADER; break;
            case MOTI_FRAGMENT_SHADER_MAGIC: m_type = GL_FRAGMENT_SHADER; break;
            default:
                MOTI_ASSERT(0, "unkown shader format %x", magic);
                break;
            }

            int32_t shaderSize;
            moti::read(&reader, shaderSize);

            m_id = glCreateShader(m_type);
            const char* src = reinterpret_cast<const char*>(reader.getPointer());

            GL_CHECK(glShaderSource(m_id, 1, (const GLchar**)&src, NULL));
            GL_CHECK(glCompileShader(m_id));

            GLint compiled(0);
            GL_CHECK(glGetShaderiv(m_id, GL_COMPILE_STATUS, &compiled));

            if (compiled == 0) {
                GLsizei len;
                char log[1024];
                GL_CHECK(glGetShaderInfoLog(m_id, sizeof(log), &len, log));
                MOTI_TRACE("Failed to compile shader %d: %s", compiled, log);
                GL_CHECK(glDeleteShader(m_id));
                m_id = 0;
            }
        }
예제 #7
0
파일: more.c 프로젝트: pali/util-linux
/* Check whether the file named by fs is an ASCII file which the user may
 * access.  If it is, return the opened file.  Otherwise return NULL. */
static FILE *checkf(register char *fs, int *clearfirst)
{
	struct stat stbuf;
	register FILE *f;
	int c;

	if (stat(fs, &stbuf) == -1) {
		fflush(stdout);
		if (clreol)
			cleareol();
		warn(_("stat of %s failed"), fs);
		return ((FILE *)NULL);
	}
	if ((stbuf.st_mode & S_IFMT) == S_IFDIR) {
		printf(_("\n*** %s: directory ***\n\n"), fs);
		return ((FILE *)NULL);
	}
	if ((f = Fopen(fs, "r")) == NULL) {
		fflush(stdout);
		warn(_("cannot open %s"), fs);
		return ((FILE *)NULL);
	}
	if (magic(f, fs)) {
		fclose(f);
		return ((FILE *)NULL);
	}
	fcntl(fileno(f), F_SETFD, FD_CLOEXEC);
	c = Getc(f);
	*clearfirst = (c == '\f');
	Ungetc(c, f);
	if ((file_size = stbuf.st_size) == 0)
		file_size = LONG_MAX;
	return (f);
}
예제 #8
0
extern int
chmod(const char* path, mode_t mode)
{
	int	r;
	int	oerrno;
	char	buf[PATH_MAX];

	if ((r = syschmod(path, mode)) && errno == ENOENT && execrate(path, buf, sizeof(buf), 0))
	{
		errno = oerrno;
		return syschmod(buf, mode);
	}
	if (!(r = syschmod(path, mode)) &&
	    (mode & (S_IXUSR|S_IXGRP|S_IXOTH)) &&
	    !suffix(path) &&
	    (strlen(path) + 4) < sizeof(buf))
	{
		oerrno = errno;
		if (!magic(path, NiL))
		{
			snprintf(buf, sizeof(buf), "%s.exe", path);
			sysrename(path, buf);
		}
		errno = oerrno;
	}
	return r;
}
예제 #9
0
파일: magic.c 프로젝트: AmitKrJoshi/LDP
int main(int argc, char *argv[])
{	
	
	int **a,n,i;

	if(argc != 2)
	{	printf("Usage: %s <magic sqaure order>\n", argv[0]);
		exit(0);
	}
	n = atoi(argv[1]);
	if(n % 2 == 0)
	{	printf("Sorry !!! I don't know how to create magic square of even order\n");
		printf("The order should be an odd number\n");
		exit(0);
	}
	a = (int **) malloc(n * sizeof(int*));
	for(i = 0;i < n;++i)
		a[i] = (int *)malloc(n * sizeof(int));

	magic(a,n);
	
	initscr();
	curs_set(0);
	noecho();
	magic_board(a,n);
	getch();
	endwin();

	return;
}
예제 #10
0
VirtualRig* VirtualKPA::loadRig(const QString& rigFilePath)
{
  QFile kiprFile(rigFilePath);

  VirtualRig* newRig = nullptr;

  kiprFile.open(QIODevice::ReadOnly);
  QDataStream stream(&kiprFile);
  qint64 fileSize = kiprFile.bytesAvailable();
  ByteArray magic(4,0x00);
  stream.readRawData((char*)magic.data(), 4);
  if(magic == sKiprMagic1 || magic == sKiprMagic2)
  {
    newRig = new VirtualRig(rigFilePath, magic);
    if(!newRig->load(stream, fileSize))
    {
      delete newRig;
      newRig = nullptr;
    }
  }

  if(newRig)
    mCurrentRig = newRig;

  return newRig;
}
예제 #11
0
/* accounting packets may be directed to any TACACS+ server,
 * independent from those used for authentication and authorization;
 * it may be also directed to all specified servers
 */
PAM_EXTERN
int pam_sm_open_session (pam_handle_t * pamh, int flags,
    int argc, const char **argv) {

    task_id=(short int) magic();
    return _pam_account(pamh, argc, argv, TAC_PLUS_ACCT_FLAG_START, NULL);
}    /* pam_sm_open_session */
예제 #12
0
int main(int argc, char *argv[])
{
	emul_init(&argc, argv);
	lcd_init();

	coord_t x = 0, y = LCD_WIDTH / 2;
	coord_t xdir = +1, ydir = -1;
	Bitmap *bm = &lcd_bitmap;

	for(;;)
	{
		gfx_bitmapClear(bm);
		gfx_setClipRect(bm, 0, 0, bm->width, bm->height);
		gfx_rectDraw(bm, 10, 10, bm->width-10, bm->height-10);
		gfx_setClipRect(bm, 11, 11, bm->width-11, bm->height-11);
		magic(bm, x, y);

		x += xdir;
		y += ydir;
		if (x >= bm->width)  xdir = -1;
		if (x <= -50)        xdir = +1;
		if (y >= bm->height) ydir = -1;
		if (y <= -50)        ydir = +1;

		lcd_blit_bitmap(bm);
		emul_idle();
		usleep(10000);
	}

	emul_cleanup();
	return 0;
}
예제 #13
0
파일: paulosif.c 프로젝트: kingcope/LikeOS
static err_t low_level_output (struct genericif *genericif, struct pbuf *p)
{
    struct pbuf *q;
    int len = p->tot_len;

    magic (p, PBUF_MAGIC);

    if (mem_usage_percent ((size_t) 0) > MEM_USAGE_HIGH) {	/* suppress packet output */
	printf ("low_level_output: memory low - dropping packet\n");	/* FIXME: remove this debug line */
	return ERR_OK;
    }

    if (enable_packet_dump)
	packet_dump (p->payload, (int) p->len, "OUT ");

    if (ioctl (genericif->fd, FIONWRITE, &len))
	die ("driver could not allocate space for packet");
    if (p->tot_len == len) {
	for (q = p; q != NULL && len > 0; q = q->next) {
	    int r;
	    if ((r = write (genericif->fd, q->payload, q->len)) != q->len)
		die ("driver could not send packet returned %d/%d, [%s] ", r, q->len, strerror (errno));
	    len -= q->len;
	}

	if (len != 0)
	    die ("len != 0, p = %p", (void *) p);
    }
    return ERR_OK;
}
예제 #14
0
파일: filesys.c 프로젝트: ljalves/FUZIX
void i_deref(inoptr ino)
{
    magic(ino);

    if(!ino->c_refs)
        panic("inode freed.");

    if((ino->c_node.i_mode & F_MASK) == F_PIPE)
        wakeup((char *)ino);

    /* If the inode has no links and no refs, it must have
       its blocks freed. */

    if(!(--ino->c_refs || ino->c_node.i_nlink))
        /*
           SN (mcy)
           */
        if(((ino->c_node.i_mode & F_MASK) == F_REG) ||
                ((ino->c_node.i_mode & F_MASK) == F_DIR) ||
                ((ino->c_node.i_mode & F_MASK) == F_PIPE))
            f_trunc(ino);

    /* If the inode was modified, we must write it to disk. */
    if(!(ino->c_refs) && ino->c_dirty)
    {
        if(!(ino->c_node.i_nlink))
        {
            ino->c_node.i_mode = 0;
            i_free(ino->c_dev, ino->c_num);
        }
        wr_inode(ino);
    }
}
예제 #15
0
header_t	*get_header(int *flag, int fd, int *l)
{
  header_t	*header;
  int		error;

  error = 0;
  header = NULL;
  if ((header = malloc(sizeof(*header))) == NULL)
    my_merror();
  if (get_name(fd, header, l) == EXIT_FAILURE)
    {
      my_printf("Asm: Name invalid at line %d.\n", *l);
      error++;
    }
  if (get_comment(fd, header, l) == EXIT_FAILURE)
    {
      my_printf("Asm: Comment invalid at line %d.\n", *l);
      error++;
    }
  if (get_extend(flag, fd, l) == EXIT_FAILURE)
    error++;
  if (error || !header)
    return (NULL);
  header->magic = magic(COREWAR_EXEC_MAGIC);
  return (header);
}
예제 #16
0
/* Returns pre-filled TACACS+ packet header of given type.
 * 1. you MUST fill th->datalength and th->version
 * 2. you MAY fill th->encryption
 * 3. you are responsible for freeing allocated header 
 * By default packet encryption is enabled. The version
 * field depends on the TACACS+ request type and thus it
 * cannot be predefined.
 */
HDR *
_tac_req_header(u_char type, u_char seq_no)
{
    HDR *th;

    if (call_magic_init) {
	magic_init();
	call_magic_init = FALSE;
    }

    th = (HDR *) xcalloc(1, TAC_PLUS_HDR_SIZE);

    /* preset some packet options in header */
    th->type = type;
    th->seq_no = seq_no;
    th->encryption = TAC_PLUS_ENCRYPTED;
 
    /* make session_id from pseudo-random number */
    if (seq_no == TAC_PLUS_INIT_SEQNO) {
	session_id = magic();
    }
    th->session_id = htonl(session_id);

    return(th);
}
예제 #17
0
파일: mtree.c 프로젝트: taysom/tau
static int insert_branch (
    tree_s		*tree,
    branch_s	*parent,
    u32		key,
    void		*rec,
    unint		size)
{
    void		*child;
    s64		k;	/* Critical that this be signed */
    FN;
    for (;;) {
        do {
            k = binary_search_branch(key, parent->br_key,
                                     parent->br_num);
            child = parent->br_key[k].k_node;
            if (!child) {
                return qERR_NOT_FOUND;
            }
        } while (split_node(tree, parent, child, k, size));
        if (magic(child) != BRANCH) {
            return insert_node(tree, child, key, rec, size);
        }
        parent = child;
    }
}
예제 #18
0
파일: thread.cpp 프로젝트: jadesoul/libsoul
bool thread::start(bool blocking, bool verbose) {
	if (running) {
		magic("thread: thread already running\n");
		return false;
	}
	// have to put this here because the thread can be running
	// before the call to create it returns
	running   = true;
#ifdef OS_WIN32
	// InitializeCriticalSection(&critSec);
	// unsigned long _beginthreadex(
		// void *security,
		// unsigned stack_size,
		// unsigned ( __stdcall *start_address )( void * ),
		// void *arglist,
		// unsigned initflag,
		// unsigned *thrdaddr
	// );
	myThread = (HANDLE)_beginthreadex(NULL, 0, this->run,  (void *)this, 0, NULL);
#else
	// pthread_mutex_init(&myMutex, NULL);
	pthread_create(&myThread, NULL, run, (void *)this);
#endif
	this->blocking=blocking;
	return true;
}
예제 #19
0
파일: more.c 프로젝트: aalm/obsd-src
/*
 * Check whether the file named by fs is an ASCII file which the user may
 * access.  If it is, return the opened file. Otherwise return NULL.
 */
FILE *
checkf(char *fs, int *clearfirst)
{
	struct stat stbuf;
	FILE *f;
	int ch;

	if (stat(fs, &stbuf) == -1) {
		(void)fflush(stdout);
		if (clreol)
			cleareol();
		perror(fs);
		return (NULL);
	}
	if ((stbuf.st_mode & S_IFMT) == S_IFDIR) {
		printf("\n*** %s: directory ***\n\n", fs);
		return (NULL);
	}
	if ((f = Fopen(fs, "r")) == NULL) {
		(void)fflush(stdout);
		perror(fs);
		return (NULL);
	}
	if (magic(f, fs))
		return (NULL);
	ch = Getc(f);
	*clearfirst = (ch == '\f');
	Ungetc(ch, f);
	if ((file_size = stbuf.st_size) == 0)
		file_size = LONG_MAX;
	return (f);
}
예제 #20
0
파일: Assert.c 프로젝트: ajn123/C_Tutorial
int main(void) {
	int a = 4;
	int * Ptr = &a;
	magic(10,Ptr);
	puts("done");
	return 0;
}
예제 #21
0
파일: mtree.c 프로젝트: taysom/tau
//XXX: Might be better to join to the left rather than the right
static int join_node (tree_s *tree, branch_s *parent, snint k)
{
    void	*child;
    int	rc;
    FN;
    if (k == parent->br_num - 1) {
        /* no sibling to the right */
        return 0;
    }
    child = parent->br_key[k].k_node;
    if (!child) return qERR_NOT_FOUND;

    switch (magic(child)) {
    case LEAF:
        rc = join_leaf(tree, parent, child, k);
        break;
    case BRANCH:
        rc = join_branch(tree, parent, child, k);
        break;
    default:
        rc = qERR_BAD_BLOCK;
        break;
    }
    return rc;
}
예제 #22
0
void VoicePrint::resizeEvent(QResizeEvent *)
{
	mOffset=0;
	mBuffer.resize(size());
	QPainter paint(&mBuffer);
	paint.fillRect(QRect(0,0, QWidget::width(), height()), QColor(mLowColor));
	setBands(magic(height()/mSegmentWidth));
}
예제 #23
0
int main()
{
    int height;
    printf ("Enter height:\n");
    scanf ("%d", &height);

    magic (height);

}
예제 #24
0
static int search_node (tree_s *tree, void *node, u64 key, search_f sf, void *data)
{
FN;
	switch (magic(node)) {
	case LEAF:	return search_leaf(tree, node, key, sf, data);
	case BRANCH:	return search_branch(tree, node, key, sf, data);
	default:	return qERR_BAD_BLOCK;
	}
}
예제 #25
0
파일: thread.cpp 프로젝트: jadesoul/libsoul
bool thread::unlock() {
#ifdef OS_WIN32
	LeaveCriticalSection(&critSec);
#else
	pthread_mutex_unlock(&myMutex);
#endif
	magic("thread: we are out -- mutext is now unlocked \n");
	return true;
}
예제 #26
0
파일: mtree.c 프로젝트: wtaysom/tau
static int insert_node (tree_s *tree, void *node, u64 key, void *rec, unint size)
{
FN;
	switch (magic(node)) {
	case LEAF:	return insert_leaf(tree, node, key, rec, size);
	case BRANCH:	return insert_branch(tree, node, key, rec, size);
	default:	return qERR_BAD_BLOCK;
	}
}
예제 #27
0
파일: lcp.c 프로젝트: AoLaD/rtems
/*
 * lcp_resetci - Reset our CI.
 */
static void
lcp_resetci(
    fsm *f)
{
    lcp_wantoptions[f->unit].magicnumber = magic();
    lcp_wantoptions[f->unit].numloops = 0;
    lcp_gotoptions[f->unit] = lcp_wantoptions[f->unit];
    peer_mru[f->unit] = PPP_MRU;
    auth_reset(f->unit);
}
예제 #28
0
static void *binary(char *ciphertext)
{
	static char b[BINARY_SIZE];
	char *p;
	memset(b, 0, BINARY_SIZE);
	p = strrchr(ciphertext, '$');
	if(p!=NULL)
	magic(p+1, b);
	return (void *) b;
}
/*
 * magic_random_bytes - Fill a buffer with random bytes.
 */
void magic_random_bytes(unsigned char *buf, u32_t buf_len) {
  u32_t new_rand, n;

  while (buf_len > 0) {
    new_rand = magic();
    n = LWIP_MIN(buf_len, sizeof(new_rand));
    MEMCPY(buf, &new_rand, n);
    buf += n;
    buf_len -= n;
  }
}
예제 #30
0
bool TbinMapFormat::supportsFile(const QString &fileName) const
{
    std::ifstream file(fileName.toStdString(), std::ios::in | std::ios::binary);
    if (!file)
        return false;

    std::string magic(6, '\0');
    file.read(&magic[ 0 ], magic.length());

    return magic == "tBIN10";
}