C++ (Cpp) strncpy Examples

C++ (Cpp) strncpy - 30 examples found. These are the top rated real world C++ (Cpp) examples of strncpy extracted from open source projects. You can rate examples to help us improve the quality of examples.
int main(int argc, char** argv) {
    key_t key = ftok("/tmp/msg.temp", 0);
    if(key < 0) {
        perror("Error getting token");
        return 1;
    }

    int msqid = msgget(key, IPC_CREAT | 0660);
    if(msqid < 0) {
        perror("Error creating message queue");
        return 2;
    }

    struct message strm;
    memset(&strm, 0, sizeof(struct message));
    strm.mtype = 1;


    if(argc > 1) strncpy(strm.mtext, argv[1], 80);
    else strncpy(strm.mtext, "Hello!", 80);

    int res = msgsnd(msqid, &strm, sizeof(struct message) - sizeof(long), 0);

    return 0;
}
Example #2
0
LogContainer::LogContainer(const char* shortName, const char* fullName, bool enable)
    : m_enable(enable)
{
    strncpy(m_fullName, fullName, 128);
    strncpy(m_shortName, shortName, 32);
    m_level = LogTypes::LDEBUG;
}
Example #3
0
bool CIPAddress::ParseStr(const char* address)
{
    u_int32_t a,b,c,d;
    char temp[10];
    char addrtmp[256];
    strcpy(addrtmp, address);

    char* q=addrtmp;
    char* p=strchr(q,'.');
    strncpy(temp,q,p-q);
    temp[p-q]='\0';
    sscanf(temp,"%d",&a);

    q=p+1;
    p=strchr(q,'.');
    strncpy(temp,q,p-q);
    temp[p-q]='\0';
    sscanf(temp,"%d",&b);

    q=p+1;
    p=strchr(q,'.');
    strncpy(temp,q,p-q);
    temp[p-q]='\0';
    sscanf(temp,"%d",&c);

    q=p+1;
    sscanf(q,"%d",&d);

    m_address=(a<<24)|(b<<16)|(c<<8)|d;

    return true;
}
Example #4
0
File: pandora.c Project: zhouqt/kbs
int load_data(struct _select_def* conf,int pos,int len)
{
    FILE *fp;
    char t[256], *t1, *t2, *t3, *t4;

    fp = fopen(DATAFILE, "r");
    conf->item_count=0;
    if (fp == NULL)
        return SHOW_REFRESH;
    while (fgets(t, 255, fp) && conf->item_count < MAXSTATION) {
        t1 = strtok(t, " \t");
        t2 = strtok(NULL, " \t\n");
        t3 = strtok(NULL, " \t\n");
        t4 = strtok(NULL, " \t\n");
        if (t1[0] == '#' || t1 == NULL || t2 == NULL || t3 == NULL)
            continue;
        strncpy(host1[conf->item_count], t1, 16);
        strncpy(host2[conf->item_count], t2, 36);
        strncpy(ip[conf->item_count], t3, 36);
        port[conf->item_count] = t4 ? atoi(t4) : 23;
        conf->item_count++;
    }
    fclose(fp);

    conf->item_per_page = conf->item_count;
    bbsnet_redraw=true;
    return SHOW_REFRESH;
}
/* ARGSUSED */
void
dk_getdefaultlabel(struct dk_intf *di, struct dk_softc *dksc,
                   struct disklabel *lp)
{
    struct disk_geom *dg = &dksc->sc_dkdev.dk_geom;

    memset(lp, 0, sizeof(*lp));

    lp->d_secperunit = dg->dg_secperunit;
    lp->d_secsize = dg->dg_secsize;
    lp->d_nsectors = dg->dg_nsectors;
    lp->d_ntracks = dg->dg_ntracks;
    lp->d_ncylinders = dg->dg_ncylinders;
    lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;

    strncpy(lp->d_typename, di->di_dkname, sizeof(lp->d_typename));
    lp->d_type = di->di_dtype;
    strncpy(lp->d_packname, "fictitious", sizeof(lp->d_packname));
    lp->d_rpm = 3600;
    lp->d_interleave = 1;
    lp->d_flags = 0;

    lp->d_partitions[RAW_PART].p_offset = 0;
    lp->d_partitions[RAW_PART].p_size = dg->dg_secperunit;
    lp->d_partitions[RAW_PART].p_fstype = FS_UNUSED;
    lp->d_npartitions = RAW_PART + 1;

    lp->d_magic = DISKMAGIC;
    lp->d_magic2 = DISKMAGIC;
    lp->d_checksum = dkcksum(dksc->sc_dkdev.dk_label);
}
Example #6
0
int
validate_ipv6_addr_param (const char *str)
{
    if (!str)
        return 0;
    char value[87];
    char ipv6_1[43];
    char ipv6_2[43];
    memset(ipv6_1, '\0', 43);
    memset(ipv6_2, '\0', 43);
    if (sscanf(str, "!%87s", value) == 1)
        str = value;
    if (re_match(str, "^[^-]+-[^-]+$")) {
        char *dash = strrchr(str, '-');
        strncpy(ipv6_1, str, dash - str);
        strncpy(ipv6_2, dash+1, strchr(str,'\0') - dash+1);
        if (validate_ipv6(ipv6_1))
            return validate_ipv6(ipv6_2);
        else
            return 0;
    }
    if (strchr(str, '/') != NULL)
        return validate_ipv6net(str);
    else
        return validate_ipv6(str);
}