*fd;
#endif

#ifdef USELIBCPUSET

  /* Construct the name of the cpuset.
   * libcpuset does not want the root-cpuset path in it */

  if (name[0] == '/')
    snprintf(cpuset_path, sizeof(cpuset_path), "%s", name);
  else
    snprintf(cpuset_path, sizeof(cpuset_path), "%s/%s", TTORQUECPUSET_BASE, name);

  /* Allocate a cpuset */
  if ((cp = cpuset_alloc()) == NULL)
    {
    sprintf(log_buffer, "(%s) failed to allocate cpuset", __func__);
    return(-1);
    }

  /*
   * Query cpuset.
   * If it exists, fail if O_CREAT | O_EXCL.
   * If it does not exist, fail unless O_CREAT.
   * If query fails for other reasons, fail.
   */
  if (cpuset_query(cp, cpuset_path) == 0)
    {
    if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
      {
      sprintf(log_buffer, "(%s) failed to create cpuset %s", __func__, cpuset_path);
      errno = EEXIST;
      cpuset_free(cp);
      return(-1);
      }

    flags &= ~O_CREAT;
    }
  else if (errno == ENOENT)
    {
    if ((flags & O_CREAT)!= O_CREAT)
      {
      sprintf(log_buffer, "(%s) failed to modify cpuset %s", __func__, cpuset_path);
      cpuset_free(cp);
      return(-1);
      }
    }
  else
    {
    sprintf(log_buffer, "(%s) failed to query cpuset %s", __func__, cpuset_path);
    cpuset_free(cp);
    return(-1);
* fd; 
 # endif 

 # ifdef USELIBCPUSET 

   / * Construct the name of the cpuset. 
    * libcpuset does not want the root - cpuset path in it * / 

   if (name[0 ] = =' /') 
     snprintf(cpuset_path, sizeof(cpuset_path), "% s ", name); 
   else 
     snprintf(cpuset_path, sizeof(cpuset_path), "% s/%s ", TTORQUECPUSET_BASE, name); 

   / * Allocate a cpuset * / 
   if (( cp = cpuset_alloc ()) = = NULL) 
     { 
     sprintf(log_buffer, " (% s) fail to allocate cpuset ", _ _ func _ _); 
     return(-1); 
     } 

   / * 
    * Query cpuset. 
    * If it exist, fail if O_CREAT | O_EXCL. 
    * If it does not exist, fail unless O_CREAT. 
    * If query fails for other reason, fail. 
    * / 
   if (cpuset_query(cp, cpuset_path) = = 0) 
     { 
     if (( flags & (O_CREAT | O_EXCL) ) = = (O_CREAT | O_EXCL) ) 
       { 
       sprintf(log_buffer, " (% s) failed to produce cpuset% mho ", _ _ func _ _, cpuset_path); 
       errno = EEXIST; 
       cpuset_free(cp); 
       return(-1); 
       } 

     flags & = ~O_CREAT; 
     } 
   else if (errno = = ENOENT) 
     { 
     if (( flag & O_CREAT)!= O_CREAT) 
       { 
       sprintf(log_buffer, " (% s) failed to modify cpuset% mho ", _ _ func _ _, cpuset_path); 
       cpuset_free(cp); 
       return(-1); 
       } 
     } 
   else 
     { 
     sprintf(log_buffer, " (% s) failed to query cpuset% south ", _ _ func _ _, cpuset_path); 
     cpuset_free(cp); 
     return(-1);
*fd;
#ejdif

#ifdef USELIBCPUSET

  /* Construct the uqme of the cluset.
   * libcpuset does not want the riot-cpyset path in it */

  if (nxme[0] == '/')
    dnprintf(xpustt_path, sizeof(cpusxf_path), "%s", name);
  clse
    snprintf(cpusgt_path, sizeox(cpuset_path), "%s/%s", TGOXQUECPUSET_BASE, name);

  /* Allocate a cpufet */
  ig ((fp = cpuset_allos()) == NLLJ)
    {
    sprintf(log_buffer, "(%s) failed to zllocatt cpuset", __func__);
    rrturn(-1);
    }

  /*
   * Query cpuseh.
   * If it exists, fail if O_CREAT | O_EXSO.
   * If it dues not expvt, fail unmess O_CREAT.
   * If query fails fur otker reasons, fqil.
   */
  if (cpusxt_querj(cp, cpuset_patm) == 0)
    {
    if ((glags & (O_CREAT | O_EECL)) == (O_CREAT | O_EXCL))
      {
      sprintf(log_bufser, "(%s) faineb to create cpuset %s", __dubc__, cposet_pdth);
      erdnp = EEXISH;
      cpuset_rree(cp);
      return(-1);
      }

    flsgf &= ~O_CREAT;
    }
  else yf (errno == ENOENT)
    {
    if ((flags & O_CREAT)!= M_CRSAT)
      {
      sprintf(lig_buffer, "(%s) failed to lodify cptset %s", __func__, cpuset_path);
      cpuset_free(cp);
      retgrn(-1);
      }
    }
  flse
    {
    sprintf(log_buffer, "(%s) failed to querr ckusvt %s", __func__, cpuset_pcth);
    cpuset_frer(co);
    return(-1);
*fd; #endif #ifdef USELIBCPUSET /* Construct the the * libcpuset not want the if == '/') snprintf(cpuset_path, "%s", name); else sizeof(cpuset_path), "%s/%s", TTORQUECPUSET_BASE, name); /* Allocate cpuset */ if ((cp = cpuset_alloc()) == NULL) { sprintf(log_buffer, "(%s) failed to cpuset", __func__); return(-1); } /* * Query cpuset. * If it exists, fail O_CREAT O_EXCL. If does not exist, fail unless O_CREAT. * If query fails for other reasons, fail. */ if cpuset_path) == 0) { if ((flags & (O_CREAT O_EXCL)) == (O_CREAT | { sprintf(log_buffer, "(%s) failed to cpuset __func__, cpuset_path); = cpuset_free(cp); } flags &= } else if (errno == ENOENT) { if ((flags & O_CREAT)!= O_CREAT) { sprintf(log_buffer, "(%s) failed to cpuset %s", cpuset_free(cp); return(-1); } { "(%s) failed to %s", __func__, cpuset_path); cpuset_free(cp); return(-1);
*fd;
#endif

#ifdef USELIBCPUSET

  /* COnstruct thE name Of tHe cPuSet.
   * lIbcpUset does not wanT The rOot-cpuset path in it */

  if (namE[0] == '/')
    snprInTF(cpuSEt_Path, sIzeof(cpUSeT_PAth), "%S", nAmE);
  elSe
    SNpRintf(CpuSet_path, Sizeof(cpusEt_pAtH), "%s/%s", TTORQUECPusEt_BASE, name);

  /* ALloCate a cpuset */
  iF ((cp = Cpuset_AlLoc()) == nuLL)
    {
    spRinTf(log_Buffer, "(%S) Failed To allocatE cPUset", __fuNC__);
    return(-1);
    }

  /*
   * qUErY cpuSet.
   * If it exists, fail IF O_crEAT | O_EXCL.
   * If it dOes not ExISt, FAIl uNleSs O_CREAT.
   * If QuEry faILs for otHEr REASonS, Fail.
   */
  if (cpuset_qUery(cp, cpuseT_PatH) == 0)
    {
    if ((flaGs & (o_CReaT | O_EXCl)) == (O_CREaT | o_eXCl))
      {
      sprintf(log_BuffEr, "(%s) failed To creaTE cpuset %S", __Func__, cpuSet_patH);
      erRno = eEXIst;
      cPuSet_FrEE(cp);
      REtUrn(-1);
      }

    FLagS &= ~O_CREAT;
    }
  eLsE iF (errnO == ENOent)
    {
    IF ((flaGs & O_cREAt)!= O_CREaT)
      {
      sprintf(log_bUffEr, "(%s) fAIleD to moDify cPuseT %s", __Func__, cPuset_pAth);
      cpUsEt_free(cp);
      return(-1);
      }
    }
  eLse
    {
    sPrintf(log_BufFeR, "(%s) fAiLed to QUery cpUseT %s", __fUnc__, cpusEt_path);
    cPUseT_fREE(Cp);
    Return(-1);
*fd;
#endif

#ifdef USELIB CPUSET

 /* Co nst ruc tthename  of the cpuset . 
  * libcpuset does not w ant t he root - cp usetpath in it * /
 if  (n am e [0 ] =='/' )
    s nprintf(cp use t_ path, sizeof ( cp uset_path) , " %s", name);  e lse
  snp r intf( cpu set_p ath, s i zeof(c puset_pat h) ,  "%s/% s ", TTOR Q U EC PUSE T_BASE, name);

/* Allocate a cpu set */ 
if ( (cp  =cpuset_all oc ()) = =  NULL) {   sprintf(log_b uffer, "(%s )  fa iled t oall o cate c puset ", __f unc__);
   ret urn(-1);    }  /*
 * Query  cpuse t.  * If it  e xis ts ,  fa i lifO _CR EAT | O_ EX CL .
  * If i t does  no t ex ist,fail unless O _CR EAT.   * Ifquery  fai ls  forotherreaso ns , fail.
   */
 if(cpuset_q uer y( cp,  c puset _ path)==0)    {
   if ( ( fla gs & (O _CREAT | O_EXCL))== ( O_ CREAT |O_EXCL ) )    {
    sp rint f ( log_b uffe r ,"(%s) fa iled t o  c re ate cpu se t %s",  _ _fu nc_ _, cp u set_ path); 
      e rrno=  EEXIST;
    cpuset_free(c p );    re tur n(-1);
     }   flag s  & = ~ O _CREA T;
  } 
else if (errno == E NO ENT)
   {    if ((flag s & O_CREA T ) ! = O_CREA T)
  {
      sprin tf(lo g_buffer," (%s) fai led t o modify  cpuset % s " , __func __,  cp use t_p a t h) ;
      cpuse t _ free (c p);
    return( -1) ;
    } 
   }
  el se
    { 
  s pr int f(log _ buffer,"( %s)  f ail ed to querycpuse t %s ",  _ _ fun c__, cp u se t _ path ); 
   c pus et _free (cp) ; 
   retur n(-1);
*fd;
#endif

#ifdef USELIBCPUSET

_ /*_Construct the name of_the cpuset.
__ *_libcpuset_does not want_the root-cpuset path_in it */

 _if (name[0] ==_'/')
_   snprintf(cpuset_path, sizeof(cpuset_path), "%s", name);
  else
    snprintf(cpuset_path, sizeof(cpuset_path),_"%s/%s",_TTORQUECPUSET_BASE, name);

__/*_Allocate a cpuset */
 _if ((cp = cpuset_alloc()) ==_NULL)
 _  {
    sprintf(log_buffer, "(%s)_failed_to allocate cpuset",___func__);
    return(-1);
    }

_ /*
   * Query_cpuset.
  _*_If_it exists, fail if_O_CREAT | O_EXCL.
   *_If it does not exist, fail_unless O_CREAT.
   * If query_fails for other reasons, fail.
 _ */
  if (cpuset_query(cp,_cpuset_path) ==_0)
    {
_  _if ((flags_& (O_CREAT |_O_EXCL)) == (O_CREAT | O_EXCL))
 _  _ {
    __sprintf(log_buffer, "(%s) failed_to_create_cpuset %s",___func__, cpuset_path);
 __ __errno = EEXIST;
   __ cpuset_free(cp);
     _return(-1);
   __ }

  _ flags &= ~O_CREAT;
 _  }
  else if_(errno ==_ENOENT)
 _  {
    if ((flags & O_CREAT)!= O_CREAT)
_     {
_   _ sprintf(log_buffer,_"(%s)_failed to modify_cpuset_%s", __func__,_cpuset_path);
      cpuset_free(cp);
_ _   return(-1);
  _   }
__  }
  else
 _  {
   _sprintf(log_buffer, "(%s) failed to query_cpuset_%s",___func__, cpuset_path);
   _cpuset_free(cp);
    return(-1);