This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

semget() API fails when run from CMD.exe but works from SH.exe


I would like my Cygwin programs to work from a DOS (CMD.exe) window, but I
am
having problems with some API calls. Here is a simple program that tries to
create
a semaphore ? it works fine when it is run from sh.exe (or in a mintty
window), but
it crashes when run in a DOS window. (The Cygwin service is running.)

Is there a way to make it work in both environments?

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <sys/msg.h>
#include <sys/errno.h>

void main()
{
        int master_semid, ftok_int;
        key_t semkey;
        int semkey_int;
        char semkeyfile[256];

        /* use this executable to generate a key */
        strcpy(semkeyfile, "semcreate.exe");

        /* generate a key from it */
        ftok_int=((int)(0xd4) & 0x000000ff);
        semkey = ftok(semkeyfile, ftok_int);
        if (semkey == -1) {
                fprintf(stderr, "ftok(%s, %d) failed\n", semkeyfile,
ftok_int);
                exit(32);
        }
        semkey_int=semkey;

        /* get the id from the key */
       master_semid = semget(semkey_int,8,0777|IPC_CREAT|IPC_EXCL);
        fprintf(stderr, "semget(%d,8,0777|create) returned %d --
errno=%d\n", semkey_int, master_semid, errno);
        if (master_semid == -1) {
                fprintf(stderr, "semaphore error\n");
        }
        exit(0);
}

Steve Bardwell
LBM Systems


Attachment: cygcheck.out
Description: Binary data

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]